Type inference with null literals and nullable reference types #55466
Labels
Area-Compilers
Feature - Nullable Reference Types
Nullable Reference Types
Resolution-Duplicate
The described behavior is tracked in another issue
I'm having trouble with the compiler not inferring the expected type for a generic method when nullable reference types are enabled and one of the arguments is the
null
literal. Consider the following code:In all these examples, my expectation is that the inferred type should be
V<string?>
and there should be no warning. But only theV("", default)
example follows that expectation.When looking at the NRT spec, I see this:
As far as I can tell, in all of these cases the second argument should produce a lower bound of
null
ordefault
, so the inferred type should bestring?
.So, am I correct and is this a bug in the compiler? Or did I misunderstood the spec and this is the expected behavior?
The text was updated successfully, but these errors were encountered: