Skip to content

Trimmer implementation of type hierarchy marking shows order dependent behavior #86580

@vitek-karas

Description

@vitek-karas

This bug is only observable after a fix from: #86635
But the bug exists in the code base today, it's just that without the PR above it actually shows even wrong marking behavior.

class UseByDerived
{
    [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
    class AnnotatedBase
    {
        [RequiresUnreferencedCode("--AnnotatedBase.VirtualMethodWithRequires--")]
        public virtual void VirtualMethodWithRequires() { }
    }

    // BUG
    // IL2113 - AnnotatedBase.VirtualMethodWithRequires
    class Derived : AnnotatedBase
    {
        [RequiresUnreferencedCode("--Derived.VirtualMethodWithRequires--")]
        public override void VirtualMethodWithRequires() { }
    }

    static void TestMethodOnDerived(Derived instance)
    {
        instance.GetType().GetMethod("MethodWithRequires");
    }

    public static void Test()
    {
        TestMethodOnDerived(new Derived());
    }
}

In the above example, the type hierarchy marking is triggered by:

Derived instance;
instance.GetType()...

In this case the trimmer produces IL2113 because the marking is first triggered on Derived and that triggers marking of methods which show up as accessible through Derived but declared on Base (IL2113 is for methods from base, IL2112 is for method on the type itself).

But if the same is triggered by:

AnnotatedBase instance;
instance.GetType()...

Then there will be no IL2113 instead there will be IL2112 on the Base.VirtualMethodWithRequires directly.

So if the program has both access patterns in it, then the diagnostics behavior is dependent on which order trimmer will process it in. The behavior should be consistent.

Metadata

Metadata

Assignees

Labels

area-Tools-ILLink.NET linker development as well as trimming analyzersin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions