Skip to content

Type argument nullability warning no longer reported for type parameter constrained to 'int?' #46410

@cston

Description

@cston

A warning should be reported for M<T>(t) since T is constrained to int? which does not satisfy the notnull constraint.

#nullable enable
abstract class A<T, U> where T : notnull
{
    internal static void M<V>(V v) where V : T { }
    internal abstract void F<V>(V v) where V : U;
}
class B : A<System.ValueType, int?>
{
    internal override void F<T>(T t)
    {
        M<T>(t);
    }
}

This may be a regression from #45993. Earlier builds reported:

(11,9): warning CS8631: The type 'T' cannot be used as type parameter 'V' in the generic type or method
    'A<ValueType, int?>.M<V>(V)'. Nullability of type argument 'T' doesn't match constraint type 'System.ValueType'.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions