fix: Dynamic code snippets now recognize bare Object and Random calls consistently

Merged
HA
3mo ago
+310-69

Summary

  • Dynamic code snippets that call Random.Range(...) without an explicit using now compile, matching the existing bare-Object support.
  • The bare-alias detection now understands comments and global using forms, 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 Object calls were auto-resolved; a bare Random.Range(...) in dynamic code failed to compile unless the user added using Random = UnityEngine.Random; manually. A global using alias with a comment in between tokens was also missed.
  • After: both Object and Random are 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

  • SourceShaper now collects every using-alias name the snippet defines (AliasedNames), replacing the old ad-hoc string scan that only recognized "Object".
  • WrapperTemplate injects default aliases (Object, Random) from a small table, skipping any name already in AliasedNames.
  • Fixed a related gap where a comment between global and using caused 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 warnings
  • dist/darwin-arm64/uloop run-tests (EditMode, full suite) — 1725 passed, 0 failed, 7 skipped (pre-existing skips)