Skip to content

Unexpected different between inferred type argument nullability and explicit #34844

@gafter

Description

@gafter

The issue regards type inference in M3 versus M4 below. Both should have the same annotation for the type argument, either unannotated, or oblivious. Which it is may depend on the outcome of #34843, but in any case they should be the same. And yet we report diagnostics for the type arguments in M3 but not in M4. It is possible that the problem is that we do not check the inferred type argument against the constraints in M4. Either way, they should be treated the same and either there should be warnings on both or neither.

See also #30214

#nullable disable
class A<T1, T2, T3> where T2 : class where T3 : object
{
    T1 F1;
    T2 F2;
    T3 F3;
    B F4;

#nullable enable
    void M3()
    {
        C.Test<T1>(); // warning given here
        C.Test<T2>(); // warning given here
        C.Test<T3>(); // warning given here
    }

    void M4()
    {
        D.Test(F1); // no warning given here
        D.Test(F2); // no warning given here
        D.Test(F3); // no warning given here
        D.Test(F4);
    }
}

class B {}

class C
{
    public static void Test<T>() where T : object
    {}
}

class D
{
    public static void Test<T>(T x) where T : object
    {}
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions