fix: InstanceValuesInTestClassAnalyzer uses return instead of continue (#4859)#4906
Merged
fix: InstanceValuesInTestClassAnalyzer uses return instead of continue (#4859)#4906
Conversation
…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
Contributor
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. The fix is correct: |
This was referenced Feb 22, 2026
Open
This was referenced Feb 23, 2026
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
InstanceValuesInTestClassAnalyzer.AnalyzeOperationwhere areturnstatement inside aforeachloop exits the entire method instead of usingcontinueto skip to the next field/propertyfieldsAndProperties, if the assignment target's containing type doesn't match the test class, only the current iteration should be skipped -- not the entire analysisDetails
In
TUnit.Analyzers/InstanceValuesInTestClassAnalyzer.csaround line 59, theforeachloop overfieldsAndPropertieshad areturn;that would exit theAnalyzeOperationmethod entirely when the target symbol's containing type didn't match the test class. This has been changed tocontinue;so the loop properly continues checking the remaining fields and properties.Closes #4859
Test plan
Do_Not_Flag_When_Not_Assigning_To_New_Classtest covers this scenario)