Skip to content

Conversation

@sailro
Copy link
Member

@sailro sailro commented Jan 9, 2026

Fixes #428

Checklist

  • I have read the Contribution Guide ;
  • There is an approved issue describing the change when contributing a new analyzer or suppressor ;
  • I have added tests that prove my fix is effective or that my feature works ;
  • I have added necessary documentation (if appropriate) ;

@sailro sailro requested a review from a team as a code owner January 9, 2026 14:22
@sailro sailro requested review from a team and Copilot and removed request for a team January 9, 2026 14:22
Copy link

Copilot AI left a 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 DetectExpressionReuse method 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.

Copy link
Contributor

Copilot AI commented Jan 9, 2026

@sailro I've opened a new pull request, #430, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits January 9, 2026 17:18
…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>
@sailro sailro merged commit 894deea into main Jan 9, 2026
5 checks passed
@sailro sailro deleted the fix-UNT0022 branch January 9, 2026 16:54
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.

UNT0022 changes behavior if transform is used in rotation update

3 participants