Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitek Karas <10670590+vitek-karas@users.noreply.github.com>2022-09-02 21:06:45 +0300
committerGitHub <noreply@github.com>2022-09-02 21:06:45 +0300
commit5f9bfd94d9c687207872ae03f751ea19704381c0 (patch)
treebdfa320f5f6968d87dfd7eca2ef9c679dbff6ad2
parent05d216f414e4173df383805fd2cb2d4124f58a15 (diff)
[release/7.0] Fixes a null ref which happens when an XML comment cref contains generic instantiation (#3020)
* Fixes a null ref which happens when an XML comment cref contains generic instantiation (#3015) * Fixes a null ref which happens when an XML comment cref contains generic instantiation In the cref some of the symbols (for example the type argument) are missing containing symbols, which leads to null refs. In any case, we should not perform any analysis on symbols inside crefs, only on real code. So this modifies the analyzer to ignore any symbol inside a cref. Adds a test to validate this. * Simplify the test * Fix the test to work on slightly older analyzer
-rw-r--r--src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs2
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs26
2 files changed, 27 insertions, 1 deletions
diff --git a/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs b/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
index 0e095dbc5..8466d2f21 100644
--- a/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
+++ b/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
@@ -128,7 +128,7 @@ namespace ILLink.RoslynAnalyzer
invocationExpression.Expression is IdentifierNameSyntax ident1 &&
ident1.Identifier.ValueText.Equals ("nameof"))
return;
- else if (parentNode is NameMemberCrefSyntax)
+ else if (parentNode is CrefSyntax)
return;
parentNode = parentNode.Parent;
diff --git a/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs b/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
index 90a7de166..9c16e43d9 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs
@@ -1357,5 +1357,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).WithArguments ("TInner", "CRequires<TInner>", "TOuter", "C<TOuter>", "'DynamicallyAccessedMemberTypes.PublicMethods'"));
+ }
}
}