Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
James Terwilliger committed Jan 26, 2024
1 parent 43e9232 commit 015c678
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
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

0 comments on commit 015c678

Please sign in to comment.