Skip to content

Reject Long defaults outside the 64-bit range [patch] - #225

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/219-long-default-range
Sep 29, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/219-long-default-range

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #219

What was wrong

ValidateMemberDefault range-checked whole-number defaults for Int with FitsInt32, but had no equivalent for Long. NumberDefault.Value is a double, so a default such as 1e19 passed validation. The C# generator then saturated it to long.MaxValue, and the C++ generator emitted an undefined double-to-std::int64_t conversion. Writing long.MaxValue exactly (9223372036854775807) had the same result, because as a double it rounds to 2^63.

Change

  • Added FitsInt64 next to FitsInt32, with a strict upper bound (< 9223372036854775808.0), since (double)long.MaxValue == 2^63.
  • A Long member 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, -1e19 and 9223372036854775807 are rejected.
  • ADefaultInsideInt64RangeOnALongMemberIsAccepted: 9223372036854774784 (the largest double below 2^63) and long.MinValue are accepted.

With the Schema.Validation.cs change reverted, all three rejection rows fail. With the change, the full Schema.Test suite 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-changes reports 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

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
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit cff76f9 into main Sep 29, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the fix/219-long-default-range branch September 29, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants