-
Notifications
You must be signed in to change notification settings - Fork 83
Fixes UNT0022, when reusing transform #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request fixes issue #428 in the UNT0022 analyzer, which incorrectly suggested combining separate transform.position and transform.rotation assignments into a single SetPositionAndRotation call when doing so would change the code's semantics. The fix adds detection for cases where the first property being set is referenced in the calculation of the second property.
Key changes:
- Added
DetectExpressionReusemethod to check if the first statement's property is referenced in the second statement - Integrated the reuse detection into the analysis flow to prevent incorrect optimization suggestions
- Added comprehensive test coverage for both unsafe (direct reuse) and safe (variable-based) scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Microsoft.Unity.Analyzers/BasePositionAndRotation.cs | Added expression reuse detection to prevent semantically incorrect optimizations |
| src/Microsoft.Unity.Analyzers.Tests/SetPositionAndRotationTests.cs | Added tests for expression reuse scenarios, including both cases that should and shouldn't be optimized |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ysis (#430) * Initial plan * Refactor string comparisons to use semantic analysis with SemanticModel Co-authored-by: sailro <638167+sailro@users.noreply.github.com> * Add test cases for semantic equivalence detection Co-authored-by: sailro <638167+sailro@users.noreply.github.com> * Add comments clarifying null symbol handling for ambiguous cases Co-authored-by: sailro <638167+sailro@users.noreply.github.com> * Fix semantic equivalence to compare entire expression chains recursively Co-authored-by: sailro <638167+sailro@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sailro <638167+sailro@users.noreply.github.com>
Fixes #428
Checklist