Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/6.0.2xx] Propagate Interfaces annotation through Type.BaseType #2476

Merged
merged 2 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/linker/Linker.Dataflow/ReflectionMethodBodyScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,9 @@ public override bool HandleCall (MethodBody callingMethodBody, MethodReference c

if (dynamicallyAccessedMemberNode.DynamicallyAccessedMemberTypes.HasFlag (DynamicallyAccessedMemberTypes.PublicProperties))
propagatedMemberTypes |= DynamicallyAccessedMemberTypes.PublicProperties;

if (dynamicallyAccessedMemberNode.DynamicallyAccessedMemberTypes.HasFlag (DynamicallyAccessedMemberTypes.Interfaces))
propagatedMemberTypes |= DynamicallyAccessedMemberTypes.Interfaces;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating a mask here and &'ing, instead of checking each flag individually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, whether inclusion of exclusion is preferred, i.e. if we forget to update this, would we prefer to propagate more or less?

}

methodReturnValue = MergePointValue.MergeValues (methodReturnValue, CreateMethodReturnValue (calledMethod, propagatedMemberTypes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public static void Main ()
TestNonPublicNestedTypesAreNotPropagated (typeof (TestType));
TestNonPublicPropertiesAreNotPropagated (typeof (TestType));

TestInterfacesPropagated (typeof (TestType));

TestCombinationOfPublicsIsPropagated (typeof (TestType));
TestCombinationOfNonPublicsIsNotPropagated (typeof (TestType));
TestCombinationOfPublicAndNonPublicsPropagatesPublicOnly (typeof (TestType));
Expand Down Expand Up @@ -164,6 +166,12 @@ static void TestNonPublicPropertiesAreNotPropagated ([DynamicallyAccessedMembers
derivedType.BaseType.RequiresNonPublicProperties ();
}

[RecognizedReflectionAccessPattern]
static void TestInterfacesPropagated ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.Interfaces)] Type derivedType)
{
derivedType.BaseType.RequiresInterfaces ();
}

[RecognizedReflectionAccessPattern]
static void TestCombinationOfPublicsIsPropagated (
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.PublicProperties)] Type derivedType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public static void Main ()
TestUnkownIgnoreCase3Params (1);
TestUnkownIgnoreCase5Params (1);
TestGenericTypeWithAnnotations ();

BaseTypeInterfaces.Test ();
}

[Kept]
Expand Down Expand Up @@ -409,5 +411,41 @@ static void TestGenericTypeWithAnnotations ()
" 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 ();
}
}
}
}