Skip to content

fix: Dynamic code snippets can use Unity Object without ambiguity#1234

Merged
hatayama merged 1 commit into
v3-betafrom
feature/hatayama/fix-dynamic-code-object-ambiguity
May 28, 2026
Merged

fix: Dynamic code snippets can use Unity Object without ambiguity#1234
hatayama merged 1 commit into
v3-betafrom
feature/hatayama/fix-dynamic-code-object-ambiguity

Conversation

@hatayama

@hatayama hatayama commented May 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • Dynamic code snippets can use Unity Object APIs without hitting the CS0104 ambiguous Object compile error.
  • Existing snippets that explicitly alias Object continue to keep their chosen alias.

User Impact

  • Before, common Unity snippets that referenced Object could fail because System and UnityEngine both expose Object.
  • Now script-mode snippets default Object to UnityEngine.Object, while object and System.Object remain available when users need them.

Changes

  • Add a wrapper-level Object alias for script-mode dynamic code.
  • Detect explicit user Object aliases, including compact spacing and comments between alias tokens, and avoid injecting the default alias in those cases.
  • Add EditMode coverage for Unity Object, System.Object, compact alias, and commented alias snippets.

Verification

  • Packages/src/Cli~/dist/darwin-arm64/uloop compile --project-path <PROJECT_ROOT>
  • Packages/src/Cli~/dist/darwin-arm64/uloop run-tests --project-path <PROJECT_ROOT> --test-mode EditMode --filter-type regex --filter-value "io.github.hatayama.UnityCliLoop.Tests.Editor.DynamicCodeToolTests.(PreUsingResolver.|AutoInjectedNamespaces.)"
  • ~/.codex/skills/codex-review/scripts/codex-review v3-beta --parallel-tests

Map naked Object to UnityEngine.Object in script-mode snippets so common Unity APIs avoid CS0104 while preserving explicit user Object aliases.
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: abd4de2a-92aa-4922-8f6a-dbcbed96b946

📥 Commits

Reviewing files that changed from the base of the PR and between 2e06e75 and 2835de1.

📒 Files selected for processing (2)
  • Assets/Tests/Editor/DynamicCodeToolTests/PreUsingResolverTests.cs
  • Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/WrapperTemplate.cs

📝 Walkthrough

Walkthrough

The PR adds conditional injection of the Object alias in dynamically compiled scripts. WrapperTemplate.Build now checks for existing Object aliases before emitting its default, and helper methods robustly detect alias directives while handling comments and whitespace. Four integration tests validate that the default alias is used when missing and user-provided aliases are preserved in various formatting styles.

Changes

Object Alias Conditional Injection

Layer / File(s) Summary
Conditional Object alias injection logic
Packages/src/Editor/FirstPartyTools/ExecuteDynamicCode/DynamicCompilation/WrapperTemplate.cs
WrapperTemplate.Build conditionally emits using Object = UnityEngine.Object; only when usingDirectives lack an Object alias. New private helpers (HasObjectAlias, IsObjectAliasDirective, SkipWhitespaceAndComments, IsCommentStart) robustly detect existing aliases while skipping whitespace and both single-line and block comments.
Script mode Object alias integration tests
Assets/Tests/Editor/DynamicCodeToolTests/PreUsingResolverTests.cs
Four async test methods validate that the wrapper injects its default Object alias only when absent, and that user-defined aliases are preserved across normal, compact-spacing, and comment-separated using Object = ... forms.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: enabling dynamic code snippets to use Unity Object without CS0104 ambiguity errors.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem, solution, user impact, and changes made to handle Object aliases in dynamic code compilation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/hatayama/fix-dynamic-code-object-ambiguity

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@hatayama
hatayama merged commit 0428197 into v3-beta May 28, 2026
8 checks passed
@hatayama
hatayama deleted the feature/hatayama/fix-dynamic-code-object-ambiguity branch May 28, 2026 12:42
@github-actions github-actions Bot mentioned this pull request May 28, 2026
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.

1 participant