dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.37k stars 4.75k forks source link

ILC: redundant warnings for annotation mismatch on static DIM #104702

Open sbomer opened 4 months ago

sbomer commented 4 months ago

ILC produces warnings for RequiresUnreferencedCode/DynamicallyAccessedMembers mismatch on virtual methods. In some scenarios, the warnings are generated while processing a callsite in generic code. This can result in redundant warnings, for example:

using System.Diagnostics.CodeAnalysis;

Call<S>();

[RequiresUnreferencedCode("M")]
static void Call<T>() where T: I {
    T.M();
    T.M();
    T.M();
}

interface I {
    [RequiresUnreferencedCode("M")]
    static abstract void M();
}

interface DIM : I {
    static void I.M() {} // Multiple IL2046 warnings, one for each T.M() callsite above.
}

struct S : DIM {}
dotnet-policy-service[bot] commented 4 months ago

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in area-owners.md if you want to be subscribed.

dotnet-policy-service[bot] commented 4 months ago

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas See info in area-owners.md if you want to be subscribed.