Skip to content

Incorrect trim analysis warning for base method implementing interface #97676

Closed

Description

@sbomer

When a type provides an interface implementation via a base method, there can be new unexpected trim analysis warnings pointing to the base method. For example:

interface I {
    void M();
}

class Base {
    [RequiresUnreferencedCode("Message")]
    public void M() { }
}

This code is fine on its own, and produces no trim analysis warnings. Now if another piece of code has:

class Derived : Base, I {}

this causes a new warning to appear at Base.M:

interface I {
    void M();
}

class Base {
    [RequiresUnreferencedCode("Message")]
    public void M() { } // warning IL2046: Member 'Base.M()' with 'RequiresUnreferencedCodeAttribute' implements interface member 'I.M()' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides.
}

In general, the derived class could be defined in another assembly, leading to trim warnings that "blame" a correctly annotated assembly. The warning should instead point to Derived, similar to what happens if there's a mismatch in the base/interface signatures:

interface I {
    void M();
}

class Base {
    public int M() { }
}

class Derived : Base, I { } // error CS0738: 'Derived' does not implement interface member 'I.M()'. 'Base.M()' cannot implement 'I.M()' because it does not have the matching return type of 'void'.

ILLink, NativeAot, and the ILLink Roslyn analyzer all share the problematic behavior.

Activity

  1. ghost added
    untriaged
    on Jan 29, 2024
  2. added
    area-Tools-ILLink
    on Jan 29, 2024
  3. removed
    untriaged
    on Jan 29, 2024
  4. added this to the 9.0.0 milestone on Apr 25, 2024
  5. added
    in-pr
    on Jul 11, 2024
  6. locked and limited conversation to collaborators on Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-NativeAOT-coreclrarea-Tools-ILLinkin-pr

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions