-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix trim warnings for base method implementing interface (#104753)
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: ```csharp 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: ```csharp class Derived : Base, I {} ``` this causes a new warning to appear at Base.M: ```csharp 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: ```csharp 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'. ``` This fixes the problematic behavior by producing the warning from the derived type instead, in ILLink, Native AOT, and the ILLink Roslyn analyzer.
- Loading branch information
Showing
11 changed files
with
445 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.