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-01-07 12:24:48 +0300
committerGitHub <noreply@github.com>2022-01-07 12:24:48 +0300
commit5b33e3ad8f422d002ffe84700a0e51b976391f2b (patch)
tree68a4ac142821f83ca2074bd273324bcfa5cf5a8d
parente28b7f3f306bb410a8a1a2f4b80f413fdea4ce86 (diff)
[release/6.0.2xx] Propagate Interfaces annotation through Type.BaseType (#2476)
The Interfaces annotation makes sure the type has all interfaces, meaning `GetInterfaces` reflection call will work on it. That means that all interfaces of the base type are also preserved, so the `Interfaces` annotation should be propagated to the base type as well.
-rw-r--r--src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs3
-rw-r--r--test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs8
-rw-r--r--test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs38
3 files changed, 49 insertions, 0 deletions
diff --git a/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs b/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs
index d90565b6d..476e86bcf 100644
--- a/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs
+++ b/src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs
@@ -1294,6 +1294,9 @@ namespace Mono.Linker.Dataflow
if (dynamicallyAccessedMemberNode.DynamicallyAccessedMemberTypes.HasFlag (DynamicallyAccessedMemberTypes.PublicProperties))
propagatedMemberTypes |= DynamicallyAccessedMemberTypes.PublicProperties;
+
+ if (dynamicallyAccessedMemberNode.DynamicallyAccessedMemberTypes.HasFlag (DynamicallyAccessedMemberTypes.Interfaces))
+ propagatedMemberTypes |= DynamicallyAccessedMemberTypes.Interfaces;
}
methodReturnValue = MergePointValue.MergeValues (methodReturnValue, CreateMethodReturnValue (calledMethod, propagatedMemberTypes));
diff --git a/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs b/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs
index abe5aaada..68d232252 100644
--- a/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs
+++ b/test/Mono.Linker.Tests.Cases/DataFlow/TypeBaseTypeDataFlow.cs
@@ -34,6 +34,8 @@ namespace Mono.Linker.Tests.Cases.DataFlow
TestNonPublicNestedTypesAreNotPropagated (typeof (TestType));
TestNonPublicPropertiesAreNotPropagated (typeof (TestType));
+ TestInterfacesPropagated (typeof (TestType));
+
TestCombinationOfPublicsIsPropagated (typeof (TestType));
TestCombinationOfNonPublicsIsNotPropagated (typeof (TestType));
TestCombinationOfPublicAndNonPublicsPropagatesPublicOnly (typeof (TestType));
@@ -165,6 +167,12 @@ namespace Mono.Linker.Tests.Cases.DataFlow
}
[RecognizedReflectionAccessPattern]
+ static void TestInterfacesPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.Interfaces)] Type derivedType)
+ {
+ derivedType.BaseType.RequiresInterfaces ();
+ }
+
+ [RecognizedReflectionAccessPattern]
static void TestCombinationOfPublicsIsPropagated (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicProperties)] Type derivedType)
{
diff --git a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs
index 1907cd653..0f660e6ed 100644
--- a/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs
+++ b/test/Mono.Linker.Tests.Cases/Reflection/TypeUsedViaReflection.cs
@@ -42,6 +42,8 @@ namespace Mono.Linker.Tests.Cases.Reflection
TestUnkownIgnoreCase3Params (1);
TestUnkownIgnoreCase5Params (1);
TestGenericTypeWithAnnotations ();
+
+ BaseTypeInterfaces.Test ();
}
[Kept]
@@ -409,5 +411,41 @@ namespace Mono.Linker.Tests.Cases.Reflection
" test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null";
Type.GetType (reflectionTypeKeptString);
}
+
+ [Kept]
+ class BaseTypeInterfaces
+ {
+ [Kept]
+ interface ITest
+ {
+ [Kept]
+ void Method ();
+ }
+
+ [Kept]
+ [KeptInterface (typeof (ITest))]
+ class BaseType : ITest
+ {
+ [Kept]
+ public void Method () { }
+ }
+
+ [Kept]
+ [KeptBaseType (typeof (BaseType))]
+ [KeptInterface (typeof (ITest))]
+ class DerivedType : BaseType, ITest
+ {
+ [Kept]
+ public void Method () { }
+ }
+
+ [Kept]
+ public static void Test ()
+ {
+ ITest t = null;
+ t.Method ();
+ typeof (DerivedType).GetInterfaces ();
+ }
+ }
}
}