Reject Long defaults outside the 64-bit range [patch] - #225
Merged
Merged
Conversation
Validation range-checked whole-number defaults for Int but not for Long, so a default such as 1e19, or long.MaxValue written exactly (which rounds to 2^63 as a double), passed validation. The C# generator then clamped it and the C++ generator emitted an undefined double-to-int64 conversion. Add FitsInt64 with an exclusive upper bound next to FitsInt32. Fixes #219 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011PMSp3sjbza8Td6fxS2Kjr
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #219
What was wrong
ValidateMemberDefaultrange-checked whole-number defaults forIntwithFitsInt32, but had no equivalent forLong.NumberDefault.Valueis adouble, so a default such as1e19passed validation. The C# generator then saturated it tolong.MaxValue, and the C++ generator emitted an undefined double-to-std::int64_tconversion. Writinglong.MaxValueexactly (9223372036854775807) had the same result, because as a double it rounds to 2^63.Change
FitsInt64next toFitsInt32, with a strict upper bound (< 9223372036854775808.0), since(double)long.MaxValue == 2^63.Longmember whose whole-number default fails it gets an error:The default … is outside the 64-bit range of Long (…).The generators need no change once validation stops the value.Tests
In
MemberMetadataTests:ADefaultOutsideInt64RangeOnALongMemberIsAnError:1e19,-1e19and9223372036854775807are rejected.ADefaultInsideInt64RangeOnALongMemberIsAccepted:9223372036854774784(the largest double below 2^63) andlong.MinValueare accepted.With the
Schema.Validation.cschange reverted, all three rejection rows fail. With the change, the fullSchema.Testsuite passes on net10.0 (507/507). I couldn't run the net8.0/net9.0 legs because those runtimes aren't installed in this environment.dotnet format --verify-no-changesreports nothing on the new lines. The only IDE0002 findings are on lines this PR doesn't change.🤖 Generated with Claude Code
https://claude.ai/code/session_011PMSp3sjbza8Td6fxS2Kjr
Generated by Claude Code