Skip to content

ILLink: RUC on derived virtual should not warn if base class has RUC #108090

@sbomer

Description

@sbomer

Consider a type Base that has RequiresUnreferencedCode:

[RequiresUnreferencedCode("Base")]
class Base {
    public Base() {}

    public virtual void Instance() {}
}

It should be possible to annotate a derived class, without necessarily marking all static methods in the derived class as RUC:

class Derived : Base {
    [RequiresUnreferencedCode("Base")]
    public Derived() {}

    [RequiresUnreferencedCode("Instance")] // warning: annotation mismatch
    public override void Instance() => Helper.RUC();

    public static void Static() {}
}

[RequiresUnreferencedCode("Helper")]
class Helper {
    public static void RUC() {}
}

Today ILLink warns about mismatching annotations on Derived.Instance and Base.Instance:

Trim analysis warning IL2046: Derived.Instance(): Member 'Derived.Instance()' with 'RequiresUnreferencedCodeAttribute' overrides base member 'Base.Instance()' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides.

This should not happen. The analyzer and ILC don't produce the same warning.

(note that this scenario also produces a separate warning about Derived deriving from Base, which should also be removed, see #107660.)

Parent Item

Metadata

Metadata

Assignees

Labels

area-Tools-ILLink.NET linker development as well as trimming analyzers

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions