diff options
13 files changed, 255 insertions, 97 deletions
diff --git a/src/ILLink.RoslynAnalyzer/ISymbolExtensions.cs b/src/ILLink.RoslynAnalyzer/ISymbolExtensions.cs index a68605e11..39d7763eb 100644 --- a/src/ILLink.RoslynAnalyzer/ISymbolExtensions.cs +++ b/src/ILLink.RoslynAnalyzer/ISymbolExtensions.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -70,15 +70,29 @@ namespace ILLink.RoslynAnalyzer return overridenMember != null; } + public static SymbolDisplayFormat ILLinkTypeDisplayFormat { get; } = + new SymbolDisplayFormat ( + typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, + genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters + ); + + public static SymbolDisplayFormat ILLinkMemberDisplayFormat { get; } = + new SymbolDisplayFormat ( + typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameOnly, + genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters, + memberOptions: + SymbolDisplayMemberOptions.IncludeParameters | + SymbolDisplayMemberOptions.IncludeExplicitInterface, + parameterOptions: SymbolDisplayParameterOptions.IncludeType + ); + public static string GetDisplayName (this ISymbol symbol) { var sb = new StringBuilder (); switch (symbol) { case IFieldSymbol fieldSymbol: - sb.Append (fieldSymbol.Type); - sb.Append (" "); - sb.Append (fieldSymbol.ContainingSymbol.ToDisplayString ()); - sb.Append ("::"); + sb.Append (fieldSymbol.ContainingSymbol.ToDisplayString (ILLinkTypeDisplayFormat)); + sb.Append ("."); sb.Append (fieldSymbol.MetadataName); break; @@ -86,6 +100,19 @@ namespace ILLink.RoslynAnalyzer sb.Append (parameterSymbol.Name); break; + case IMethodSymbol methodSymbol: + // Format the declaring type with namespace and containing types. + if (methodSymbol.ContainingSymbol.Kind == SymbolKind.NamedType) { + // If the containing symbol is a method (for example for local functions), + // don't include the containing type's name. This matches the behavior of + // CSharpErrorMessageFormat. + sb.Append (methodSymbol.ContainingType.ToDisplayString (ILLinkTypeDisplayFormat)); + sb.Append ("."); + } + // Format parameter types with only type names. + sb.Append (methodSymbol.ToDisplayString (ILLinkMemberDisplayFormat)); + break; + default: sb.Append (symbol.ToDisplayString ()); break; diff --git a/src/linker/Linker/MethodReferenceExtensions.cs b/src/linker/Linker/MethodReferenceExtensions.cs index 4453520c5..edc151b73 100644 --- a/src/linker/Linker/MethodReferenceExtensions.cs +++ b/src/linker/Linker/MethodReferenceExtensions.cs @@ -28,7 +28,7 @@ namespace Mono.Linker sb.Append ("("); if (method.HasParameters) { for (int i = 0; i < method.Parameters.Count - 1; i++) - sb.Append (method.Parameters[i].ParameterType.GetDisplayNameWithoutNamespace ()).Append (','); + sb.Append (method.Parameters[i].ParameterType.GetDisplayNameWithoutNamespace ()).Append (", "); sb.Append (method.Parameters[method.Parameters.Count - 1].ParameterType.GetDisplayNameWithoutNamespace ()); } diff --git a/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs b/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs index bb5799ba8..48674779c 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs @@ -54,16 +54,16 @@ class C NeedsPublicMethodsOnParameter(type); } }"; - // (23,33): warning IL2067: 'parameter' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'C.NeedsPublicMethodsOnParameter(System.Type)'. - // The parameter 'type' of method 'C.M(System.Type)' does not have matching annotations. + // (23,33): warning IL2067: 'parameter' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'C.NeedsPublicMethodsOnParameter(Type)'. + // The parameter 'type' of method 'C.M(Type)' 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. return VerifyDynamicallyAccessedMembersAnalyzer (TargetParameterWithAnnotations, VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchParameterTargetsParameter) .WithSpan (23, 33, 23, 37) .WithArguments ("parameter", - "C.NeedsPublicMethodsOnParameter(System.Type)", + "C.NeedsPublicMethodsOnParameter(Type)", "type", - "C.M(System.Type)", + "C.M(Type)", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } @@ -92,15 +92,15 @@ class C } }"; - // (19,9): warning IL2068: 'C.M(System.Type)' method return value does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' requirements. - // The parameter 'type' of method 'C.M(System.Type)' does not have matching annotations. + // (19,9): warning IL2068: 'C.M(Type)' method return value does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' requirements. + // The parameter 'type' of method 'C.M(Type)' 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. return VerifyDynamicallyAccessedMembersAnalyzer (TargetMethodReturnTypeWithAnnotations, VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchParameterTargetsMethodReturnType) .WithSpan (19, 9, 19, 21) - .WithArguments ("C.M(System.Type)", + .WithArguments ("C.M(Type)", "type", - "C.M(System.Type)", + "C.M(Type)", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } @@ -131,15 +131,15 @@ class C private static Type f = typeof(T); }"; - // (18,9): warning IL2069: value stored in field 'System.Type C::f' does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' requirements. - // The parameter 'type' of method 'C.M(System.Type)' does not have matching annotations. + // (18,9): warning IL2069: value stored in field 'C.f' does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' requirements. + // The parameter 'type' of method 'C.M(Type)' 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. return VerifyDynamicallyAccessedMembersAnalyzer (TargetFieldWithAnnotations, VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchParameterTargetsField) .WithSpan (18, 9, 18, 17) - .WithArguments ("System.Type C::f", + .WithArguments ("C.f", "type", - "C.M(System.Type)", + "C.M(Type)", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } @@ -166,15 +166,15 @@ class C } }"; - // (17,9): warning IL2070: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(string)'. - // The parameter 'type' of method 'C.M(System.Type)' does not have matching annotations. + // (17,9): warning IL2070: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(String)'. + // The parameter 'type' of method 'C.M(Type)' 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. return VerifyDynamicallyAccessedMembersAnalyzer (TargetMethodWithAnnotations, VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchParameterTargetsThisParameter) .WithSpan (17, 9, 17, 30) - .WithArguments ("System.Type.GetMethod(string)", + .WithArguments ("System.Type.GetMethod(String)", "type", - "C.M(System.Type)", + "C.M(Type)", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } #endregion @@ -209,13 +209,13 @@ class C } }"; - // (13,39): warning IL2072: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'C.NeedsPublicMethodsOnParameter(System.Type)'. + // (13,39): warning IL2072: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'C.NeedsPublicMethodsOnParameter(Type)'. // The return value of method 'C.GetT()' 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. return VerifyDynamicallyAccessedMembersAnalyzer (TargetParameterWithAnnotations, VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchMethodReturnTypeTargetsParameter) .WithSpan (13, 39, 13, 45) - .WithArguments ("type", "C.NeedsPublicMethodsOnParameter(System.Type)", "C.GetT()", "'DynamicallyAccessedMemberTypes.PublicMethods'")); + .WithArguments ("type", "C.NeedsPublicMethodsOnParameter(Type)", "C.GetT()", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } [Fact] @@ -284,13 +284,13 @@ class C private static Type f; }"; - // (13,9): warning IL2074: value stored in field 'System.Type C::f' does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' requirements. + // (13,9): warning IL2074: value stored in field 'C.f' does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' requirements. // The return value of method 'C.M()' 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. return VerifyDynamicallyAccessedMembersAnalyzer (TargetFieldWithAnnotations, VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchMethodReturnTypeTargetsField) .WithSpan (13, 9, 13, 16) - .WithArguments ("System.Type C::f", + .WithArguments ("C.f", "C.M()", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } @@ -319,13 +319,13 @@ class C } }"; - // (12,9): warning IL2075: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(string)'. + // (12,9): warning IL2075: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(String)'. // The return value of method 'C.GetT()' 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. return VerifyDynamicallyAccessedMembersAnalyzer (TargetMethodWithAnnotations, VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchMethodReturnTypeTargetsThisParameter) .WithSpan (12, 9, 12, 32) - .WithArguments ("System.Type.GetMethod(string)", "C.GetT()", "'DynamicallyAccessedMemberTypes.PublicMethods'")); + .WithArguments ("System.Type.GetMethod(String)", "C.GetT()", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } #endregion @@ -356,15 +356,15 @@ class C } }"; - // (15,28): warning IL2077: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'C.NeedsPublicMethods(System.Type)'. - // The field 'System.Type C::f' does not have matching annotations. + // (15,28): warning IL2077: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'C.NeedsPublicMethods(Type)'. + // The field 'C.f' 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. return VerifyDynamicallyAccessedMembersAnalyzer (TargetParameterWithAnnotations, VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchFieldTargetsParameter) .WithSpan (15, 28, 15, 29) .WithArguments ("type", - "C.NeedsPublicMethods(System.Type)", - "System.Type C::f", + "C.NeedsPublicMethods(Type)", + "C.f", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } @@ -396,12 +396,12 @@ class C }"; // (21,9): warning IL2078: 'C.M()' method return value does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' requirements. - // The field 'System.Type C::f' does not have matching annotations. + // The field 'C.f' 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. return VerifyDynamicallyAccessedMembersAnalyzer (TargetMethodReturnTypeWithAnnotations, VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchFieldTargetsMethodReturnType) .WithSpan (21, 9, 21, 18) - .WithArguments ("C.M()", "System.Type C::f", + .WithArguments ("C.M()", "C.f", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } @@ -428,14 +428,14 @@ class C f2 = f1; } }"; - // (18,9): warning IL2079: value stored in field 'System.Type C::f2' does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' requirements. - // The field 'System.Type C::f1' does not have matching annotations. + // (18,9): warning IL2079: value stored in field 'C.f2' does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' requirements. + // The field 'C.f1' 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. return VerifyDynamicallyAccessedMembersAnalyzer (TargetFieldWithAnnotations, VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchFieldTargetsField) .WithSpan (18, 9, 18, 16) - .WithArguments ("System.Type C::f2", - "System.Type C::f1", + .WithArguments ("C.f2", + "C.f1", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } @@ -459,14 +459,14 @@ class C } }"; - // (14,9): warning IL2080: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(string)'. - // The field 'System.Type C::f' does not have matching annotations. + // (14,9): warning IL2080: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(String)'. + // The field 'C.f' 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. return VerifyDynamicallyAccessedMembersAnalyzer (TargetMethodWithAnnotations, VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchFieldTargetsThisParameter) .WithSpan (14, 9, 14, 27) - .WithArguments ("System.Type.GetMethod(string)", - "System.Type C::f", + .WithArguments ("System.Type.GetMethod(String)", + "C.f", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } #endregion @@ -669,13 +669,13 @@ namespace System } }"; - // (178,16): warning IL2082: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.C.M2(System.Type)'. + // (178,16): warning IL2082: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.C.M2(Type)'. // The implicit 'this' argument of method 'System.C.M1()' 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. return VerifyDynamicallyAccessedMembersAnalyzer (string.Concat (GetSystemTypeBase (), TargetParameterWithAnnotations), VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchThisParameterTargetsParameter) .WithSpan (178, 16, 178, 20) - .WithArguments ("type", "System.C.M2(System.Type)", "System.C.M1()", "'DynamicallyAccessedMemberTypes.PublicMethods'")); + .WithArguments ("type", "System.C.M2(Type)", "System.C.M1()", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } [Fact] @@ -712,7 +712,7 @@ namespace System return VerifyDynamicallyAccessedMembersAnalyzer (string.Concat (GetSystemTypeBase (), ConversionOperation), VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchMethodReturnTypeTargetsParameter) .WithSpan (183, 16, 183, 36) - .WithArguments ("type", "System.C.M2(System.Type)", "System.ConvertsToType.implicit operator System.Type(System.ConvertsToType)", "'DynamicallyAccessedMemberTypes.PublicMethods'")); + .WithArguments ("type", "System.C.M2(Type)", "System.ConvertsToType.implicit operator Type(ConvertsToType)", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } @@ -752,7 +752,7 @@ namespace System return VerifyDynamicallyAccessedMembersAnalyzer (string.Concat (GetSystemTypeBase (), AnnotatedConversionOperation), VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchMethodReturnTypeTargetsParameter) .WithSpan (185, 16, 185, 36) - .WithArguments ("type", "System.C.M2(System.Type)", "System.ConvertsToType.implicit operator System.Type(System.ConvertsToType)", "'DynamicallyAccessedMemberTypes.PublicMethods'")); + .WithArguments ("type", "System.C.M2(Type)", "System.ConvertsToType.implicit operator Type(ConvertsToType)", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } [Fact] @@ -847,13 +847,13 @@ namespace System } }"; - // (178,13): warning IL2084: value stored in field 'System.Type System.C::f' does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' requirements. + // (178,13): warning IL2084: value stored in field 'System.C.f' does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' requirements. // The implicit 'this' argument of method 'System.C.M()' 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. return VerifyDynamicallyAccessedMembersAnalyzer (string.Concat (GetSystemTypeBase (), TargetFieldWithAnnotations), VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchThisParameterTargetsField) .WithSpan (178, 13, 178, 21) - .WithArguments ("System.Type System.C::f", + .WithArguments ("System.C.f", "System.C.M()", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } @@ -913,13 +913,13 @@ class C } }"; - // (19,12): warning IL2087: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'C.M1(System.Type)'. + // (19,12): warning IL2087: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'C.M1(Type)'. // The generic parameter 'T' of 'C.M2<T>()' 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. return VerifyDynamicallyAccessedMembersAnalyzer (TargetParameterWithAnnotations, VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchTypeArgumentTargetsParameter) .WithSpan (19, 12, 19, 21) - .WithArguments ("type", "C.M1(System.Type)", "T", "C.M2<T>()", "'DynamicallyAccessedMemberTypes.PublicMethods'")); + .WithArguments ("type", "C.M1(Type)", "T", "C.M2<T>()", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } [Fact] @@ -975,13 +975,13 @@ class C } }"; - // (17,9): warning IL2089: value stored in field 'System.Type C::f' does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' requirements. + // (17,9): warning IL2089: value stored in field 'C.f' does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' requirements. // The generic parameter 'T' of 'C.M<T>()' 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. return VerifyDynamicallyAccessedMembersAnalyzer (TargetFieldWithAnnotations, VerifyCS.Diagnostic (DiagnosticId.DynamicallyAccessedMembersMismatchTypeArgumentTargetsField) .WithSpan (17, 9, 17, 22) - .WithArguments ("System.Type C::f", + .WithArguments ("C.f", "T", "C.M<T>()", "'DynamicallyAccessedMemberTypes.PublicMethods'")); @@ -1018,5 +1018,58 @@ class C .WithSpan (17, 9, 17, 16) .WithArguments ("T", "C.M1<T>()", "S", "C.M2<S>()", "'DynamicallyAccessedMemberTypes.PublicMethods'")); } + + [Fact (Skip = "https://github.com/dotnet/linker/issues/2308")] + public Task SourceTypeofFlowsIntoTargetMethodReturnTypeAnnotation () + { + var TargetMethodReturnTypeWithAnnotations = @" +using System; +using System.Diagnostics.CodeAnalysis; + +public class T +{ +} + +class C +{ + public static void Main() + { + M(); + } + + [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] + private static Type M() + { + return typeof(C); + } +}"; + + return VerifyDynamicallyAccessedMembersAnalyzer (TargetMethodReturnTypeWithAnnotations); + } + + [Fact (Skip = "https://github.com/dotnet/linker/issues/2308")] + public Task SourceTypeofFlowsIntoTargetParameterAnnotations () + { + var TargetParameterWithAnnotations = @" +using System; +using System.Diagnostics.CodeAnalysis; + +public class T +{ +} + +class C +{ + public static void Main() + { + M(typeof(C)); + } + + private static void M([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type type) + { + } +}"; + return VerifyDynamicallyAccessedMembersAnalyzer (TargetParameterWithAnnotations); + } } } diff --git a/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs b/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs index 4528116d5..88d44c9bf 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/LinkerTestCases.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -28,5 +28,21 @@ namespace ILLink.RoslynAnalyzer.Tests RunTest<RequiresUnreferencedCodeAnalyzer> (m, attrs, UseMSBuildProperties (MSBuildPropertyOptionNames.EnableTrimAnalyzer)); } + + [Theory] + [MemberData (nameof (TestCaseUtils.GetTestData), parameters: nameof (DataFlow))] + public void DataFlow (string testName, MemberDeclarationSyntax m, List<AttributeSyntax> attrs) + { + switch (testName) { + case "MemberTypesRelationships": + case "MethodParametersDataFlow": + case "MethodReturnParameterDataFlow": + break; + default: + return; + } + + RunTest<DynamicallyAccessedMembersAnalyzer> (m, attrs, UseMSBuildProperties (MSBuildPropertyOptionNames.EnableTrimAnalyzer)); + } } } diff --git a/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs b/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs index 10da5a5d9..10bc20ef7 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/RequiresAssemblyFilesAnalyzerTests.cs @@ -301,7 +301,7 @@ class C }"; return VerifyRequiresAssemblyFilesAnalyzer (src, // (8,13): warning IL3001: Assemblies embedded in a single-file app cannot have additional files in the manifest. - VerifyCS.Diagnostic (DiagnosticId.AvoidAssemblyGetFilesInSingleFile).WithSpan (8, 13, 8, 41).WithArguments ("System.Reflection.Assembly.GetFile(string)"), + VerifyCS.Diagnostic (DiagnosticId.AvoidAssemblyGetFilesInSingleFile).WithSpan (8, 13, 8, 41).WithArguments ("System.Reflection.Assembly.GetFile(String)"), // (9,13): warning IL3001: Assemblies embedded in a single-file app cannot have additional files in the manifest. VerifyCS.Diagnostic (DiagnosticId.AvoidAssemblyGetFilesInSingleFile).WithSpan (9, 13, 9, 25).WithArguments ("System.Reflection.Assembly.GetFiles()") ); diff --git a/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs b/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs index fadac2914..bcf5d4052 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/TestCaseUtils.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.Collections.Generic; using System.Collections.Immutable; using System.IO; @@ -119,6 +120,13 @@ namespace ILLink.RoslynAnalyzer.Tests testAssemblyPath = Path.GetFullPath (Path.Combine (artifactsBinDir, "ILLink.RoslynAnalyzer.Tests", configDirectoryName, tfm)); } + // Accepts typeof expressions, with a format specifier + public static string GetStringFromExpression (TypeOfExpressionSyntax expr, SemanticModel semanticModel, SymbolDisplayFormat displayFormat) + { + var typeSymbol = semanticModel.GetSymbolInfo (expr.Type).Symbol; + return typeSymbol?.ToDisplayString (displayFormat) ?? throw new InvalidOperationException (); + } + // Accepts string literal expressions or binary expressions concatenating strings public static string GetStringFromExpression (ExpressionSyntax expr, SemanticModel? semanticModel = null) { @@ -143,11 +151,6 @@ namespace ILLink.RoslynAnalyzer.Tests Assert.Equal (SyntaxKind.StringLiteralToken, token.Kind ()); return token.ValueText; - case SyntaxKind.TypeOfExpression: - var typeofExpression = (TypeOfExpressionSyntax) expr; - var typeSymbol = semanticModel.GetSymbolInfo (typeofExpression.Type).Symbol; - return typeSymbol?.GetDisplayName () ?? string.Empty; - default: Assert.True (false, "Unsupported expr kind " + expr.Kind ()); return null!; diff --git a/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs b/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs index 21261a0f3..9dd5b7878 100644 --- a/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs +++ b/test/ILLink.RoslynAnalyzer.Tests/TestChecker.cs @@ -219,14 +219,18 @@ namespace ILLink.RoslynAnalyzer.Tests return false; string sourceMemberName = memberSymbol!.GetDisplayName (); - string expectedReflectionMemberMethodType = TestCaseUtils.GetStringFromExpression (args["#0"], SemanticModel); + string expectedReflectionMemberMethodType = TestCaseUtils.GetStringFromExpression ((TypeOfExpressionSyntax) args["#0"], SemanticModel, ISymbolExtensions.ILLinkTypeDisplayFormat); string expectedReflectionMemberMethodName = TestCaseUtils.GetStringFromExpression (args["#1"], SemanticModel); var reflectionMethodParameters = new List<string> (); if (args.TryGetValue ("#2", out var reflectionMethodParametersExpr) || args.TryGetValue ("reflectionMethodParameters", out reflectionMethodParametersExpr)) { if (reflectionMethodParametersExpr is ArrayCreationExpressionSyntax arrayReflectionMethodParametersExpr) { - foreach (var rmp in arrayReflectionMethodParametersExpr.Initializer!.Expressions) - reflectionMethodParameters.Add (TestCaseUtils.GetStringFromExpression (rmp, SemanticModel)); + foreach (var rmp in arrayReflectionMethodParametersExpr.Initializer!.Expressions) { + var parameterStr = rmp.Kind () == SyntaxKind.TypeOfExpression + ? TestCaseUtils.GetStringFromExpression ((TypeOfExpressionSyntax) rmp, SemanticModel, ISymbolExtensions.ILLinkMemberDisplayFormat) + : TestCaseUtils.GetStringFromExpression (rmp, SemanticModel); + reflectionMethodParameters.Add (parameterStr); + } } } diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs index bb7a69ce9..51e71b970 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/MethodParametersDataFlow.cs @@ -98,7 +98,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow type = ReturnThingsWithPublicParameterlessConstructor (); } - [ExpectedWarning ("IL2072", "'type'", "argument", nameof (LongWriteToParameterOnInstanceMethod) + "(Int32,Int32,Int32,Int32,Type)", nameof (ReturnThingsWithPublicParameterlessConstructor))] + [ExpectedWarning ("IL2072", "'type'", "argument", nameof (LongWriteToParameterOnInstanceMethod) + "(Int32, Int32, Int32, Int32, Type)", nameof (ReturnThingsWithPublicParameterlessConstructor))] private void LongWriteToParameterOnInstanceMethod ( int a, int b, int c, int d, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)] @@ -107,7 +107,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow type = ReturnThingsWithPublicParameterlessConstructor (); } - [ExpectedWarning ("IL2072", "'type'", "argument", nameof (LongWriteToParameterOnStaticMethod) + "(Int32,Int32,Int32,Int32,Type)", nameof (ReturnThingsWithPublicParameterlessConstructor))] + [ExpectedWarning ("IL2072", "'type'", "argument", nameof (LongWriteToParameterOnStaticMethod) + "(Int32, Int32, Int32, Int32, Type)", nameof (ReturnThingsWithPublicParameterlessConstructor))] private static void LongWriteToParameterOnStaticMethod ( int a, int b, int c, int d, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors)] @@ -135,7 +135,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow RequirePublicConstructors (type2); } - [UnrecognizedReflectionAccessPattern (typeof (MethodParametersDataFlow), nameof (RequirePublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2067")] + // TODO: https://github.com/dotnet/linker/issues/2273 + // (Dataflow analysis is not supported by the analyzer yet) + [ExpectedWarning ("IL2067", + nameof (MethodParametersDataFlow) + "." + nameof (RequirePublicConstructors) + "(Type)", + "type", + ProducedBy = ProducedBy.Trimmer)] private void TwoAnnotatedParametersIntoOneValue ( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type type, @@ -156,8 +161,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow } // Validate error message when untracable value is passed to an annotated parameter. - [UnrecognizedReflectionAccessPattern (typeof (MethodParametersDataFlow), nameof (RequirePublicParameterlessConstructor), new Type[] { typeof (Type) }, - messageCode: "IL2062", message: new string[] { "type", "RequirePublicParameterlessConstructor" })] + [ExpectedWarning ("IL2062", + nameof (MethodParametersDataFlow) + "." + nameof (RequirePublicParameterlessConstructor) + "(Type)", + "type", + ProducedBy = ProducedBy.Trimmer)] private void UnknownValue () { var array = new object[1]; @@ -190,7 +197,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow RequirePublicParameterlessConstructorAndNothing (typeof (TestType), this.GetType ()); } - [ExpectedWarning ("IL2098", "p1", nameof (UnsupportedParameterType))] + // TODO: https://github.com/dotnet/linker/issues/2273 + [ExpectedWarning ("IL2098", "p1", nameof (UnsupportedParameterType), ProducedBy = ProducedBy.Trimmer)] private void UnsupportedParameterType ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicFields)] object p1) { } diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs index 8dfe13492..65395c997 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/MethodReturnParameterDataFlow.cs @@ -49,6 +49,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow [UnrecognizedReflectionAccessPattern (typeof (MethodReturnParameterDataFlow), nameof (ReturnPublicParameterlessConstructor), new Type[] { typeof (Type), typeof (Type), typeof (Type) }, returnType: typeof (Type), messageCode: "IL2068")] + // TODO: https://github.com/dotnet/linker/issues/2308 + // This warning should not be produced. + [ExpectedWarning ("IL2083", + nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnPublicParameterlessConstructor) + "(Type, Type, Type)", + "'this'", + ProducedBy = ProducedBy.Analyzer)] [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type ReturnPublicParameterlessConstructor ( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] @@ -125,9 +131,10 @@ namespace Mono.Linker.Tests.Cases.DataFlow return publicConstructorsType; } - [UnrecognizedReflectionAccessPattern (typeof (MethodReturnParameterDataFlow), nameof (ReturnUnknownValue), - new Type[] { }, returnType: typeof (Type), - messageCode: "IL2063", message: new string[] { nameof (ReturnUnknownValue) })] + // TODO: https://github.com/dotnet/linker/issues/2273 + [ExpectedWarning ("IL2063", + nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnUnknownValue) + "()", + ProducedBy = ProducedBy.Trimmer)] [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicConstructors)] Type ReturnUnknownValue () { @@ -141,8 +148,32 @@ namespace Mono.Linker.Tests.Cases.DataFlow } } - [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")] - [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")] + // These warnings require dataflow analysis which the analyzer doesn't have yet: https://github.com/dotnet/linker/issues/2273 + [ExpectedWarning ("IL2072", + nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors) + "(Type)", + nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnPublicParameterlessConstructor) + "(Type, Type, Type)", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2072", + nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors) + "(Type)", + nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnPublicParameterlessConstructor) + "(Type, Type, Type)", + ProducedBy = ProducedBy.Trimmer)] + // TODO: https://github.com/dotnet/linker/issues/2308 + // These warnings should not be produced. + [ExpectedWarning ("IL2082", + nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnPublicParameterlessConstructor) + "(Type, Type, Type)", + "'this'", + nameof (MethodReturnParameterDataFlow) + "." + nameof (PropagateReturnPublicParameterlessConstructor), + ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2082", + nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnPublicParameterlessConstructor) + "(Type, Type, Type)", + "'this'", + nameof (MethodReturnParameterDataFlow) + "." + nameof (PropagateReturnPublicParameterlessConstructor), + ProducedBy = ProducedBy.Analyzer)] + [ExpectedWarning ("IL2082", + nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnPublicParameterlessConstructor) + "(Type, Type, Type)", + "'this'", + nameof (MethodReturnParameterDataFlow) + "." + nameof (PropagateReturnPublicParameterlessConstructor), + ProducedBy = ProducedBy.Analyzer)] void PropagateReturnPublicParameterlessConstructor () { Type t = ReturnPublicParameterlessConstructor (typeof (TestType), typeof (TestType), typeof (TestType)); @@ -152,8 +183,15 @@ namespace Mono.Linker.Tests.Cases.DataFlow t.RequiresNone (); } - [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")] - [UnrecognizedReflectionAccessPattern (typeof (DataFlowTypeExtensions), nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors), new Type[] { typeof (Type) }, messageCode: "IL2072")] + // These warnings require dataflow analysis which the analyzer doesn't have yet: https://github.com/dotnet/linker/issues/2273 + [ExpectedWarning ("IL2072", + nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresPublicConstructors) + "(Type)", + nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnPublicParameterlessConstructorFromConstant) + "()", + ProducedBy = ProducedBy.Trimmer)] + [ExpectedWarning ("IL2072", + nameof (DataFlowTypeExtensions) + "." + nameof (DataFlowTypeExtensions.RequiresNonPublicConstructors) + "(Type)", + nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnPublicParameterlessConstructorFromConstant) + "()", + ProducedBy = ProducedBy.Trimmer)] void PropagateReturnPublicParameterlessConstructorFromConstant () { Type t = ReturnPublicParameterlessConstructorFromConstant (); @@ -183,15 +221,17 @@ namespace Mono.Linker.Tests.Cases.DataFlow // https://github.com/dotnet/linker/issues/2025 // Ideally this should not warn - [UnrecognizedReflectionAccessPattern (typeof (MethodReturnParameterDataFlow), nameof (ReturnWithRequirementsAlwaysThrows), new Type[] { }, returnType: typeof (Type), - messageCode: "IL2063")] + [ExpectedWarning ("IL2063", + nameof (MethodReturnParameterDataFlow) + "." + nameof (ReturnWithRequirementsAlwaysThrows) + "()", + ProducedBy = ProducedBy.Trimmer)] [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type ReturnWithRequirementsAlwaysThrows () { throw new NotImplementedException (); } - [ExpectedWarning ("IL2106", nameof (UnsupportedReturnType))] + // TODO: https://github.com/dotnet/linker/issues/2273 + [ExpectedWarning ("IL2106", nameof (UnsupportedReturnType), ProducedBy = ProducedBy.Trimmer)] [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] static object UnsupportedReturnType () => null; diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs index 1907cd653..83f53e488 100644 --- a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs +++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs @@ -265,7 +265,7 @@ namespace Mono.Linker.Tests.Cases.Reflection public class CaseInsensitive { } [Kept] - [ExpectedWarning ("IL2096", "'System.Type.GetType(String,Boolean,Boolean)'")] + [ExpectedWarning ("IL2096", "'System.Type.GetType(String, Boolean, Boolean)'")] static void TestTypeUsingCaseInsensitiveFlag () { const string reflectionTypeKeptString = "mono.linker.tests.cases.reflection.TypeUsedViaReflection+CaseInsensitive, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; @@ -275,7 +275,7 @@ namespace Mono.Linker.Tests.Cases.Reflection public class CaseUnknown { } [Kept] - [ExpectedWarning ("IL2096", "'System.Type.GetType(String,Boolean,Boolean)'")] + [ExpectedWarning ("IL2096", "'System.Type.GetType(String, Boolean, Boolean)'")] static void TestTypeUsingCaseUnknownByTheLinker () { bool hideCase = GetCase (); @@ -295,7 +295,7 @@ namespace Mono.Linker.Tests.Cases.Reflection public class CaseUnknown2 { } [Kept] - [ExpectedWarning ("IL2096", "'System.Type.GetType(String,Boolean,Boolean)'")] + [ExpectedWarning ("IL2096", "'System.Type.GetType(String, Boolean, Boolean)'")] static void TestTypeUsingCaseUnknownByTheLinker2 () { const string reflectionTypeKeptString = "mono.linker.tests.cases.reflection.TypeUsedViaReflection+CaseUnknown2, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; @@ -326,7 +326,7 @@ namespace Mono.Linker.Tests.Cases.Reflection public class OverloadWith5ParametersWithIgnoreCase { } [Kept] - [ExpectedWarning ("IL2096", "'System.Type.GetType(String,Func<AssemblyName,Assembly>,Func<Assembly,String,Boolean,Type>,Boolean,Boolean)'")] + [ExpectedWarning ("IL2096", "'System.Type.GetType(String, Func<AssemblyName,Assembly>, Func<Assembly,String,Boolean,Type>, Boolean, Boolean)'")] static void TestTypeOverloadWith5ParametersWithIgnoreCase () { const string reflectionTypeKeptString = "Mono.Linker.Tests.Cases.Reflection.TypeUsedViaReflection+OverloadWith5ParametersWithIgnoreCase"; @@ -359,15 +359,15 @@ namespace Mono.Linker.Tests.Cases.Reflection } [Kept] - [ExpectedWarning ("IL2026", "'System.Reflection.Assembly.GetType(String,Boolean)'")] - [ExpectedWarning ("IL2057", "'System.Type.GetType(String,Boolean)'")] + [ExpectedWarning ("IL2026", "'System.Reflection.Assembly.GetType(String, Boolean)'")] + [ExpectedWarning ("IL2057", "'System.Type.GetType(String, Boolean)'")] static Type GetTypeFromAssembly (Assembly assembly, string name, bool caseSensitive) { return assembly == null ? Type.GetType (name, caseSensitive) : assembly.GetType (name, caseSensitive); } [Kept] - [ExpectedWarning ("IL2096", "'System.Type.GetType(String,Boolean,Boolean)'")] + [ExpectedWarning ("IL2096", "'System.Type.GetType(String, Boolean, Boolean)'")] static void TestUnkownIgnoreCase3Params (int num) { const string reflectionTypeKeptString = "mono.linker.tests.cases.reflection.TypeUsedViaReflection+CaseUnknown2, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; @@ -376,7 +376,7 @@ namespace Mono.Linker.Tests.Cases.Reflection } [Kept] - [ExpectedWarning ("IL2096", "'System.Type.GetType(String,Func<AssemblyName,Assembly>,Func<Assembly,String,Boolean,Type>,Boolean,Boolean)'")] + [ExpectedWarning ("IL2096", "'System.Type.GetType(String, Func<AssemblyName,Assembly>, Func<Assembly,String,Boolean,Type>, Boolean, Boolean)'")] static void TestUnkownIgnoreCase5Params (int num) { const string reflectionTypeKeptString = "mono.linker.tests.cases.reflection.TypeUsedViaReflection+CaseUnknown2, test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"; diff --git a/test/Mono.Linker.Tests/TestCases/Dependencies/SortedWarnings.txt b/test/Mono.Linker.Tests/TestCases/Dependencies/SortedWarnings.txt index 2ef14654e..e794e4a19 100644 --- a/test/Mono.Linker.Tests/TestCases/Dependencies/SortedWarnings.txt +++ b/test/Mono.Linker.Tests/TestCases/Dependencies/SortedWarnings.txt @@ -1,9 +1,9 @@ ILLink: Trim analysis warning IL2026: library: Using member 'Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.RUCType.RUCType()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. --RUCType--. -ILLink: Trim analysis warning IL2072: Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.NestedType.Warning3(): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Linq.Expressions.Expression.Call(Type,String,Type[],Expression[])'. The return value of method 'Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.TriggerUnrecognizedPattern()' 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. -ILLink: Trim analysis warning IL2072: Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.NestedType.Warning4<T>(List`1&): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Linq.Expressions.Expression.Call(Type,String,Type[],Expression[])'. The return value of method 'Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.TriggerUnrecognizedPattern()' 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. -ILLink: Trim analysis warning IL2072: Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.Warning2.get: '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Linq.Expressions.Expression.Call(Type,String,Type[],Expression[])'. The return value of method 'Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.TriggerUnrecognizedPattern()' 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. -ILLink: Trim analysis warning IL2072: Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.Main(): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Linq.Expressions.Expression.Call(Type,String,Type[],Expression[])'. The return value of method 'Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.TriggerUnrecognizedPattern()' 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. -ILLink: Trim analysis warning IL2072: Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.Warning1(): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Linq.Expressions.Expression.Call(Type,String,Type[],Expression[])'. The return value of method 'Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.TriggerUnrecognizedPattern()' 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. +ILLink: Trim analysis warning IL2072: Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.NestedType.Warning3(): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Linq.Expressions.Expression.Call(Type, String, Type[], Expression[])'. The return value of method 'Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.TriggerUnrecognizedPattern()' 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. +ILLink: Trim analysis warning IL2072: Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.NestedType.Warning4<T>(List`1&): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Linq.Expressions.Expression.Call(Type, String, Type[], Expression[])'. The return value of method 'Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.TriggerUnrecognizedPattern()' 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. +ILLink: Trim analysis warning IL2072: Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.Warning2.get: '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Linq.Expressions.Expression.Call(Type, String, Type[], Expression[])'. The return value of method 'Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.TriggerUnrecognizedPattern()' 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. +ILLink: Trim analysis warning IL2072: Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.Main(): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Linq.Expressions.Expression.Call(Type, String, Type[], Expression[])'. The return value of method 'Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.TriggerUnrecognizedPattern()' 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. +ILLink: Trim analysis warning IL2072: Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.Warning1(): '#0' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Linq.Expressions.Expression.Call(Type, String, Type[], Expression[])'. The return value of method 'Mono.Linker.Tests.Cases.Warnings.Dependencies.TriggerWarnings_Lib.TriggerUnrecognizedPattern()' 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. ILLink: Trim analysis warning IL2075: Mono.Linker.Tests.Cases.Warnings.Individual.WarningsAreSorted.A.X(): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(String)'. The return value of method 'System.Type.GetType(String)' 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. ILLink: Trim analysis warning IL2075: Mono.Linker.Tests.Cases.Warnings.Individual.WarningsAreSorted.A.Y(): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(String)'. The return value of method 'System.Type.GetType(String)' 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. ILLink: Trim analysis warning IL2075: Mono.Linker.Tests.Cases.Warnings.Individual.WarningsAreSorted.B.X(): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods' in call to 'System.Type.GetMethod(String)'. The return value of method 'System.Type.GetType(String)' 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. diff --git a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs index fe2b6bf8e..e62cb6203 100644 --- a/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs +++ b/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs @@ -1171,7 +1171,7 @@ namespace Mono.Linker.Tests.TestCasesRunner if (parameterTypes != null) { fullName += "("; - fullName += string.Join (",", parameterTypes.Select (pt => pt.Value switch { + fullName += string.Join (", ", parameterTypes.Select (pt => pt.Value switch { TypeReference typeRef => typeRef.GetDisplayNameWithoutNamespace ().ToString (), string str => str, _ => throw new NotImplementedException () @@ -1232,7 +1232,6 @@ namespace Mono.Linker.Tests.TestCasesRunner // parameter, and the full member name of the member which declares the generic parameter will be // returned via the out parameter. - genericMember = null; if (member == null) return null; diff --git a/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs b/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs index b025aae92..715adbaed 100644 --- a/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs +++ b/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs @@ -23,22 +23,30 @@ namespace Mono.Linker.Tests switch (member.MetadataToken.TokenType) { case TokenType.TypeRef: case TokenType.TypeDef: - var x = (member as TypeReference).GetDisplayName (); Assert.AreEqual (expectedDisplayName, (member as TypeReference).GetDisplayName ()); break; case TokenType.MemberRef: case TokenType.Method: - var y = (member as MethodReference).GetDisplayName (); Assert.AreEqual (expectedDisplayName, (member as MethodReference).GetDisplayName ()); break; + case TokenType.Field: + Assert.AreEqual (expectedDisplayName, (member as FieldReference).GetDisplayName ()); + break; default: throw new NotImplementedException (); } - } public static IEnumerable<TestCaseData> GetMemberAssertions (Type type) => MemberAssertionsCollector.GetMemberAssertionsData (type); + [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.Field")] + public int Field; + + [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.MultipleParameters(Int32, Int32)")] + public void MultipleParameters (int a, int b) + { + } + [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.A")] public class A { @@ -127,7 +135,7 @@ namespace Mono.Linker.Tests [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.GenericClassOneParameter<T>.NestedGenericClassOneParameter<S>.Delegate<U>")] public delegate void Delegate<U> (U p); - [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.GenericClassOneParameter<T>.NestedGenericClassOneParameter<S>.MethodGenericArray<U,V>(IList<U>,V)")] + [DisplayName ("Mono.Linker.Tests.GetDisplayNameTests.GenericClassOneParameter<T>.NestedGenericClassOneParameter<S>.MethodGenericArray<U,V>(IList<U>, V)")] public void MethodGenericArray<U, V> (IList<U> p, V q) { } |