Skip to content

Commit 157a520

Browse files
authored
Merge pull request #606 from microsoft/dev/aphistra/VSMEF003-generictype-exports
Check exported type for unbound types instead.
2 parents 0748908 + 68d434c commit 157a520

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Microsoft.VisualStudio.Composition.Analyzers/VSMEF003ExportTypeMismatchAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private static bool IsTypeCompatible(INamedTypeSymbol implementingType, INamedTy
155155
// Check if implementing type implements exported interface
156156
if (exportedType.TypeKind == TypeKind.Interface)
157157
{
158-
return implementingType.AllInterfaces.Any(i => SymbolEqualityComparer.Default.Equals(i.IsGenericType ? i.ConstructUnboundGenericType() : i, exportedType));
158+
return implementingType.AllInterfaces.Any(i => SymbolEqualityComparer.Default.Equals(exportedType.IsUnboundGenericType ? i.ConstructUnboundGenericType() : i, exportedType));
159159
}
160160

161161
return false;

test/Microsoft.VisualStudio.Composition.Analyzers.Tests/VSMEF003ExportTypeMismatchAnalyzerTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,33 @@ class Test : ITest
4040
await VerifyCS.VerifyAnalyzerAsync(test);
4141
}
4242

43+
[Fact]
44+
public async Task ExportingImplementedMultiTypeInterface_ProducesNoDiagnostic()
45+
{
46+
string test = """
47+
using System.Composition;
48+
49+
class TestType1
50+
{
51+
}
52+
53+
class TestType2
54+
{
55+
}
56+
57+
interface ITest<T,V> where T : class where V : class
58+
{
59+
}
60+
61+
[Export(typeof(ITest<TestType1,TestType2>))]
62+
class Test : ITest<TestType1,TestType2>
63+
{
64+
}
65+
""";
66+
67+
await VerifyCS.VerifyAnalyzerAsync(test);
68+
}
69+
4370
[Fact]
4471
public async Task ExportingImplementedGenericTypeInterface_ProducesNoDiagnostic()
4572
{

0 commit comments

Comments
 (0)