diff options
Diffstat (limited to 'test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs')
-rw-r--r-- | test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs b/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs index 71e6ab82d..7acce352b 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs @@ -1378,5 +1378,31 @@ namespace System // (8,3): error CS0103: The name 'type' does not exist in the current context DiagnosticResult.CompilerError ("CS0103").WithSpan (8, 3, 8, 7).WithArguments ("type")); } + + [Fact] + public Task CRefGenericParameterAnalysis () + { + var Source = """ + using System; + using System.Diagnostics.CodeAnalysis; + + class C<TOuter> + { + /// <summary> + /// <remarks> + /// <see cref="CRequires{TOuter}.IsIt"/> + /// </remarks> + /// </summary> + static CRequires<TOuter> Value => throw new Exception(); + } + + class CRequires<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] TInner> { public static bool IsIt => false; } + """; + + // The actual usage (return value) should warn, about missing annotation, but the cref should not. + return VerifyDynamicallyAccessedMembersAnalyzer (Source, + // (11,9): warning IL2091: 'TInner' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in 'CRequires<TInner>'. The generic parameter 'TOuter' of 'C<TOuter>' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. + VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchTypeArgumentTargetsGenericParameter).WithSpan (11, 9, 11, 26).WithSpan (4, 9, 4, 15).WithArguments ("TInner", "CRequires<TInner>", "TOuter", "C<TOuter>", "'DynamicallyAccessedMemberTypes.PublicMethods'")); + } } } |