fix constant expression evaluation - #9
Merged
bea4dev merged 1 commit intoSep 26, 2026
Merged
Conversation
Bind const field initializers in their declaring file, namespace and type before evaluating an initializer that has not yet been checked. Reuse the normal expression checker instead of guessing types and resolving names from syntax, so declaration order does not change compound assignment constant conversions. Preserve uint and ulong values when evaluating shifts and complements, and parse integral literals through i128 so ulong literals above i64::MAX remain available. Evaluate integral conditional expressions with constant boolean conditions, including const locals, without accepting bool as an integral conversion. Require both branches to be constant and bound recursive field binding as well as evaluation. Add regression coverage for all six affected integral target types, declaration order, qualified constants, sizeof, shifts, complements, conditional expressions, cross-file aliases and nested types. Check that out-of-range values, nonconstants, bool operands and cycles are rejected.
ureishi
force-pushed
the
fix-constant-expression-evaluation
branch
from
September 25, 2026 18:38
f6103f2 to
ac0fede
Compare
Collaborator
|
thanks! LGTM! |
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.
Summary
Some valid compound assignments to
sbyte,byte,short,ushort,uint, andulongstill fail depending on a constant's expression or declaration order. For example,byte b = 0; b += K;rejects a laterconst int K = Other.N + 1;, even when the value fits in a byte.This change binds an unchecked constant initializer in its declaring file, namespace and type using the existing expression checker, then evaluates the typed expression. It also preserves unsigned widths for shifts and complements, handles large
ulongliterals, and evaluates integral conditional expressions with constant boolean conditions. Nonconstants and out-of-range values remain rejected.The regression tests cover declaration order across all six affected integral types, qualified constants,
sizeof, shifts, complements, conditional expressions, cross-file aliases, nested types, and rejection cases including cyclic constants.Environment
Prepared on Windows. The target project uses Unity 2022.3.22f1 and VRCSDK 3.10.5.
Notes
This change was prepared with assistance from OpenAI Codex (GPT-6). Please feel free to adjust the implementation, naming, comments or test layout to fit the project's conventions.