Skip to content

Comments

fix: InstanceValuesInTestClassAnalyzer uses return instead of continue (#4859)#4906

Merged
thomhurst merged 1 commit intomainfrom
fix/analyzer-return-continue
Feb 19, 2026
Merged

fix: InstanceValuesInTestClassAnalyzer uses return instead of continue (#4859)#4906
thomhurst merged 1 commit intomainfrom
fix/analyzer-return-continue

Conversation

@thomhurst
Copy link
Owner

Summary

  • Fix a bug in InstanceValuesInTestClassAnalyzer.AnalyzeOperation where a return statement inside a foreach loop exits the entire method instead of using continue to skip to the next field/property
  • When iterating over fieldsAndProperties, if the assignment target's containing type doesn't match the test class, only the current iteration should be skipped -- not the entire analysis

Details

In TUnit.Analyzers/InstanceValuesInTestClassAnalyzer.cs around line 59, the foreach loop over fieldsAndProperties had a return; that would exit the AnalyzeOperation method entirely when the target symbol's containing type didn't match the test class. This has been changed to continue; so the loop properly continues checking the remaining fields and properties.

Closes #4859

Test plan

  • Existing analyzer tests pass (the Do_Not_Flag_When_Not_Assigning_To_New_Class test covers this scenario)
  • Project builds successfully with zero errors

…zer foreach loop

In the foreach loop over fieldsAndProperties, a `return` statement was
exiting the entire AnalyzeOperation method when the assignment target's
containing type didn't match the test class. This should be `continue`
to skip the current field/property and keep checking the remaining ones.

Closes #4859
@claude
Copy link
Contributor

claude bot commented Feb 19, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

The fix is correct: return inside a foreach loop was prematurely exiting the entire AnalyzeOperation method when an assignment target's containing type didn't match the test class, causing all remaining fields/properties to be skipped without analysis. Replacing it with continue is the right fix — it skips only the non-matching iteration and lets the loop proceed normally. Clean, minimal, and directly addresses the described bug.

@thomhurst thomhurst merged commit a9bae7c into main Feb 19, 2026
14 checks passed
@thomhurst thomhurst deleted the fix/analyzer-return-continue branch February 19, 2026 01:04
This was referenced Feb 22, 2026
This was referenced Feb 23, 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.

bug: InstanceValuesInTestClassAnalyzer uses return instead of continue

1 participant