fix: Dynamic code snippets now recognize bare Object and Random calls consistently
Merged
HA
3mo ago+310+310+012345678901234567890123456789-69-69-01234567890123456789
Summary
- Dynamic code snippets that call
Random.Range(...)without an explicitusingnow compile, matching the existing bare-Objectsupport. - The bare-alias detection now understands comments and
global usingforms, so a snippet's own custom alias is respected even when written unusually (e.g.using @Object = ...;, or with comments between tokens).
User Impact
- Before: only bare
Objectcalls were auto-resolved; a bareRandom.Range(...)in dynamic code failed to compile unless the user addedusing Random = UnityEngine.Random;manually. Aglobal usingalias with a comment in between tokens was also missed. - After: both
ObjectandRandomare auto-resolved when the snippet doesn't already alias them, and user-defined aliases (including verbatim/comment-containing forms) are correctly detected and respected.
Changes
SourceShapernow collects every using-alias name the snippet defines (AliasedNames), replacing the old ad-hoc string scan that only recognized "Object".WrapperTemplateinjects default aliases (Object,Random) from a small table, skipping any name already inAliasedNames.- Fixed a related gap where a comment between
globalandusingcaused the directive to be misclassified as a plain statement. - Restored unit test coverage for this behavior at the preparer/shaper level (the previous coverage was removed in #1310 because it was execution-based and risked freezing the Editor; these new tests do not compile-and-run).
Verification
dist/darwin-arm64/uloop compile— 0 errors, 0 warningsdist/darwin-arm64/uloop run-tests(EditMode, full suite) — 1725 passed, 0 failed, 7 skipped (pre-existing skips)