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.
Consider a type
Base
that hasRequiresUnreferencedCode
:It should be possible to annotate a derived class, without necessarily marking all static methods in the derived class as RUC:
Today ILLink warns about mismatching annotations on Derived.Instance and Base.Instance:
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 https://github.com/dotnet/runtime/issues/107660.)