dotnet / linker

387 stars 126 forks source link

RUC should suppress warnings about generics from type #3142

Open sbomer opened 1 year ago

sbomer commented 1 year ago

RUC on type silences warnings for code in members of the type, including generics warnings for methods. But it doesn't silence warnings about generics on the type itself:

    class RequireAll<[DAM(DAMT.All)] T> {}

    [RUC("C<T>")]
    class C<T> : RequireAll<T> {} // IL2091 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.All' 

I believe RUC on type should silence this warning. I can't think of a way to do something unsafe with typeof(C<>) that wouldn't cause warnings elsewhere.

sbomer commented 1 year ago

Similar for fields:

    class G<[DAM(DAMT.PublicMethods)] T> {}

    [RUC("")]
    class CInst<T> {
        public static G<T> field; // IL2091

        public G<T> instField; // IL2091
    }

    [RequiresUnreferencedCode("")]
    public static void Test() {
        var f = new CInst<int>().instField;
        var g = CInst<int>.field;
    }

I think these cases should not warn.