Skip to content

Conversation

@fnipo
Copy link
Contributor

@fnipo fnipo commented Dec 23, 2025

Fixes xunit/xunit#3411

Added special-cases handling to MemberDataShouldReferenceValidMember.cs

  • Extracts the generic argument T from IEnumerable<T> and treats any array type (T[]) as assignable to object[]. This enables IEnumerable<string[]> to be recognized as a valid MemberData reference type.
  • Adds support for named types that are convertible to IEnumerable<T[]> by analyzing their source‑declared type syntax. As a result, classes declared such as class NamedTypeForIEnumerableStringArray : IEnumerable<string[]> are now correctly identified as valid MemberData reference types.

Alternatives explored:

  • While evaluating compilation.ClassifyConversion(fromType, toType), I found that Roslyn often reports IsImplicit = true for conversions that are not actually valid at runtime. Because of this, it isn’t a reliable mechanism for determining true assignability or convertibility between types.
  • When resolving named types, I wasn’t able to reliably extract the concrete generic argument using only ITypeSymbol / INamedTypeSymbol. For example, in the case of NamedTypeForIEnumerableStringArray class, the implemented interface appeared as IEnumerable<T> rather than IEnumerable<string[]>, which prevents inspection of the actual generic type argument. To address this, I leveraged the source‑declared type syntax instead, allowing me to accurately extract the generic argument and walk the declared base‑type chain.

Tests updated to cover these scenarios and ensure existing diagnostics remain stable.

Notes

I’d welcome any feedback on this, as it’s my first contribution to this repository. Some of the logic I introduced could potentially be folded into SymbolExtensions.IsAssignableFrom() to improve its handling of special‑case assignability scenarios, particularly where non‑exact matches are interesting. However, since that method is widely used across the codebase, I opted to implement the special‑case handling locally to avoid unintended regressions, especially given my limited familiarity with the repo.

@fnipo
Copy link
Contributor Author

fnipo commented Dec 23, 2025

@dotnet-policy-service agree

@bradwilson bradwilson merged commit 8059c4a into xunit:main Jan 14, 2026
1 check passed
@bradwilson
Copy link
Member

Thanks!

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.

xUnit1019 false positive

2 participants