Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for https://github.com/xunit/xunit/issues/2873 #179

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,38 @@ public void PuzzleOne(int _1, params string[] _2) { }
await Verify.VerifyAnalyzer(source);
}

[Fact]
public async void DoesNotFindWarning_WhenPassingTupleWithoutFieldNames()
{
var source = @"
using Xunit;

public class TestClass {
public static TheoryData<(int, int)> TestData = new TheoryData<(int, int)>();

[MemberData(nameof(TestData))]
public void TestMethod((int a, int b) x) { }
}";

await Verify.VerifyAnalyzer(LanguageVersion.CSharp8, source);
}

[Fact]
public async void DoesNotFindWarning_WhenPassingTupleWithDifferentFieldNames()
{
var source = @"
using Xunit;

public class TestClass {
public static TheoryData<(int c, int d)> TestData = new TheoryData<(int, int)>();

[MemberData(nameof(TestData))]
public void TestMethod((int a, int b) x) { }
}";

await Verify.VerifyAnalyzer(LanguageVersion.CSharp8, source);
}

[Fact]
public async void FindWarning_WithExtraValueNotCompatibleWithParamsArray()
{
Expand Down
8 changes: 8 additions & 0 deletions src/xunit.analyzers/Utility/SymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ public static bool IsAssignableFrom(
return IsAssignableFrom(targetEnumerableType, sourceEnumerableType);
}

// Special handling for tuples as tuples with differently named fields are still assignable
if (targetType.IsTupleType && sourceType.IsTupleType)
{
ITypeSymbol targetTupleType = ((INamedTypeSymbol)targetType).TupleUnderlyingType ?? targetType;
ITypeSymbol sourceTupleType = ((INamedTypeSymbol)sourceType).TupleUnderlyingType ?? sourceType;
return SymbolEqualityComparer.Default.Equals(sourceTupleType, targetTupleType);
}

if (targetType.TypeKind == TypeKind.Interface)
return sourceType.AllInterfaces.Any(i => IsAssignableFrom(targetType, i));

Expand Down
Loading