diff options
-rw-r--r-- | src/ILLink.RoslynAnalyzer/TrimAnalysis/ParameterProxy.cs | 4 | ||||
-rw-r--r-- | test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefParameterDataFlow.cs | 46 |
2 files changed, 48 insertions, 2 deletions
diff --git a/src/ILLink.RoslynAnalyzer/TrimAnalysis/ParameterProxy.cs b/src/ILLink.RoslynAnalyzer/TrimAnalysis/ParameterProxy.cs index 6ee65cbb9..fe01aeaf5 100644 --- a/src/ILLink.RoslynAnalyzer/TrimAnalysis/ParameterProxy.cs +++ b/src/ILLink.RoslynAnalyzer/TrimAnalysis/ParameterProxy.cs @@ -17,7 +17,7 @@ namespace ILLink.Shared.TypeSystemProxy public partial ReferenceKind GetReferenceKind () => IsImplicitThis - ? ((ITypeSymbol) Method.Method.ContainingSymbol).IsValueType + ? Method.Method.ContainingType.IsValueType ? ReferenceKind.Ref : ReferenceKind.None : Method.Method.Parameters[MetadataIndex].RefKind switch { @@ -54,4 +54,4 @@ namespace ILLink.Shared.TypeSystemProxy public bool IsTypeOf (WellKnownType type) => ParameterType.IsTypeOf (type); } -}
\ No newline at end of file +} diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefParameterDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefParameterDataFlow.cs index 27dda5a8c..bce67302e 100644 --- a/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefParameterDataFlow.cs +++ b/test/Mono.Linker.Tests.Cases/DataFlow/MethodByRefParameterDataFlow.cs @@ -37,6 +37,7 @@ namespace Mono.Linker.Tests.Cases.DataFlow Type nullType4 = null; TestAssigningToRefParameter_Mismatch (nullType4, ref nullType4); TestPassingRefsWithImplicitThis (); + LocalMethodsAndLambdas.Test (); } [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] @@ -190,6 +191,51 @@ namespace Mono.Linker.Tests.Cases.DataFlow { } + static class LocalMethodsAndLambdas + { + static ref Type GetTypeRefWithoutAnnotations () { throw null; } + + [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] + static ref Type GetTypeRefWithMethods () { throw null; } + + [return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] + static ref Type GetTypeRefWithMethodsAndFields () { throw null; } + + [ExpectedWarning ("IL2067", "t", "InnerMethodWithDam")] + [ExpectedWarning ("IL2067", "tWithMethodsAndFields", "InnerMethodWithDam")] + [ExpectedWarning ("IL2072", nameof (GetTypeRefWithoutAnnotations), "InnerMethodWithDam")] + [ExpectedWarning ("IL2068", nameof (GetTypeRefWithMethodsAndFields), "InnerMethodWithDam")] + static void MethodWithLocaMethodWithDam (Type t, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type tWithMethods, [DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicFields)] Type tWithMethodsAndFields) + { + // 2067 + InnerMethodWithDam (ref t); + + // Okay + InnerMethodWithDam (ref tWithMethods); + + // 2067 (but parameter of inner method targets parameter of outer method) + InnerMethodWithDam (ref tWithMethodsAndFields); + + // 2072 + InnerMethodWithDam (ref GetTypeRefWithoutAnnotations ()); + + // No warn + InnerMethodWithDam (ref GetTypeRefWithMethods ()); + + // 2068 + InnerMethodWithDam (ref GetTypeRefWithMethodsAndFields ()); + + void InnerMethodWithDam ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] ref Type typeWithMethods) + { + } + } + + public static void Test () + { + MethodWithLocaMethodWithDam (null, null, null); + } + } + #region InheritsFromType class InheritsFromType : Type { |