Skip to content

fix constant expression evaluation - #9

Merged
bea4dev merged 1 commit into
ProjectTesca:mainfrom
ureishi:fix-constant-expression-evaluation
Sep 26, 2026
Merged

bea4dev merged 1 commit into
ProjectTesca:mainfrom
ureishi:fix-constant-expression-evaluation

Conversation

@ureishi

@ureishi ureishi commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Some valid compound assignments to sbyte, byte, short, ushort, uint, and ulong still fail depending on a constant's expression or declaration order. For example, byte b = 0; b += K; rejects a later const 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 ulong literals, 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.

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
ureishi force-pushed the fix-constant-expression-evaluation branch from f6103f2 to ac0fede Compare September 25, 2026 18:38
@bea4dev

bea4dev commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

thanks! LGTM!

@bea4dev
bea4dev merged commit 9fe6f6d into ProjectTesca:main Sep 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants