Repository navigation
MemberData analyzer: analyze test methods declared in records - #232
Merged
bradwilson merged 2 commits intoSep 16, 2026
Merged
Conversation
GetClassTypesForAttribute looked for a ClassDeclarationSyntax ancestor, so test methods inside record / record class / record struct types (which are RecordDeclarationSyntax) were silently skipped by all MemberData rules. Use TypeDeclarationSyntax instead.
…cord-classes-a5be15
Member
|
Thanks! |
Member
|
Available in |
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
All MemberData rules (xUnit1014–1021, 1036–1042, 1053, …) were silently skipped for test methods declared inside a
record,record class, orrecord struct.MemberDataShouldReferenceValidMember.GetClassTypesForAttributefound the containing type withFirstAncestorOrSelf<ClassDeclarationSyntax>(). Records areRecordDeclarationSyntax, which does not derive fromClassDeclarationSyntax, so the lookup returnednulland the analyzer returned early.Repro
Fix
The lookup now uses
FirstAncestorOrSelf<TypeDeclarationSyntax>(), which matches classes, records, and structs. The two code fixers that call this helper (ExtraValueFixer,NullShouldNotBeUsedForIncompatibleParameterFixer) get the fix too.Tests
X1015_MemberDataShouldReferenceValidMemberTests.V2_and_V3test, and raised its language version from C# 8 to C# 10 sorecord structcompiles.xunit.analyzers.testsandxunit.analyzers.latest.testspass on net8.0. The net472 tests were not run because this was tested on macOS.