diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs index c3aaa62d99ba97..2d9cb6cd84160d 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs @@ -75,16 +75,22 @@ public override void ApplyCondition (FeatureChecksValue featureChecksValue, ref // - 'this' parameter (for annotated methods) // - field reference - public override MultiValue Visit (IOperation? operation, StateValue argument) + public override MultiValue DefaultVisit (IOperation operation, StateValue argument) { - var returnValue = base.Visit (operation, argument); + var returnValue = base.DefaultVisit (operation, argument); // If the return value is empty (TopValue basically) and the Operation tree // reports it as having a constant value, use that as it will automatically cover // cases we don't need/want to handle. - if (operation != null && returnValue.IsEmpty () && TryGetConstantValue (operation, out var constValue)) + if (!returnValue.IsEmpty ()) + return returnValue; + + if (TryGetConstantValue (operation, out var constValue)) return constValue; + if (operation.Type is not null) + return UnknownValue.Instance; + return returnValue; } diff --git a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/DataFlowTests.cs b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/DataFlowTests.cs index 3a95e6ea046cbd..7a8c025d65eed2 100644 --- a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/DataFlowTests.cs +++ b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/DataFlowTests.cs @@ -186,7 +186,7 @@ public Task InlineArrayDataflow () } [Fact] - public Task InterpolatedStringHandlerDataFlow () + public Task InterpolatedStringDataFlow () { return RunTest (); } diff --git a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs index a06c8115c31584..fccb0de0d95e35 100644 --- a/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs +++ b/src/tools/illink/test/ILLink.RoslynAnalyzer.Tests/DynamicallyAccessedMembersAnalyzerTests.cs @@ -1309,7 +1309,9 @@ public static void Main() return VerifyDynamicallyAccessedMembersAnalyzer (Source, consoleApplication: false, // (12,34): error CS0103: The name 'type' does not exist in the current context - DiagnosticResult.CompilerError ("CS0103").WithSpan (12, 34, 12, 38).WithArguments ("type")); + DiagnosticResult.CompilerError ("CS0103").WithSpan (12, 34, 12, 38).WithArguments ("type"), + // (12,34): warning IL2063: Value returned from method 'C.GetTypeWithAll()' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements. + VerifyCS.Diagnostic (DiagnosticId.MethodReturnValueCannotBeStaticallyDetermined).WithSpan(12, 34, 12, 38).WithArguments("C.GetTypeWithAll()")); } [Fact] @@ -1333,7 +1335,9 @@ public static void Main() return VerifyDynamicallyAccessedMembersAnalyzer (Source, consoleApplication: false, // (8,22): error CS0103: The name 'type' does not exist in the current context - DiagnosticResult.CompilerError ("CS0103").WithSpan (8, 22, 8, 26).WithArguments ("type")); + DiagnosticResult.CompilerError ("CS0103").WithSpan (8, 22, 8, 26).WithArguments ("type"), + // (8,3): warning IL2064: Value assigned to C.fieldRequiresAll can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements. + VerifyCS.Diagnostic(DiagnosticId.FieldValueCannotBeStaticallyDetermined).WithSpan(8, 3, 8, 26).WithArguments("C.fieldRequiresAll")); } [Fact] diff --git a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/InterpolatedStringHandlerDataFlow.cs b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/InterpolatedStringDataFlow.cs similarity index 77% rename from src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/InterpolatedStringHandlerDataFlow.cs rename to src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/InterpolatedStringDataFlow.cs index 6e30b600d736a5..f862348ddec336 100644 --- a/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/InterpolatedStringHandlerDataFlow.cs +++ b/src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/InterpolatedStringDataFlow.cs @@ -15,14 +15,15 @@ namespace Mono.Linker.Tests.Cases.DataFlow [ExpectedNoWarnings] [SkipKeptItemsValidation] [Define ("DEBUG")] - public class InterpolatedStringHandlerDataFlow + public class InterpolatedStringDataFlow { public static void Main () { - Test (); + TestInterpolatedStringHandler (); + TestUnknownInterpolatedString (); } - static void Test(bool b = true) { + static void TestInterpolatedStringHandler (bool b = true) { // Creates a control-flow graph for the analyzer that has an // IFlowCaptureReferenceOperation that represents a capture // because it is used as an out param (so has IsInitialization = true). @@ -31,5 +32,10 @@ static void Test(bool b = true) { // where IsInitialization = true. Debug.Assert (b, $"Debug interpolated string handler {b}"); } + + [ExpectedWarning ("IL2057")] + static void TestUnknownInterpolatedString (string input = "test") { + Type.GetType ($"{input}"); + } } }