Closed as not planned
Description
Consider the following code:
void function(int? arg1, int? arg2) {
switch ((arg1, arg2)) {
case (null, null): print("both null");
case (var first, null): print(first.abs());
case (null, var second): print(second.abs());
}
}
To a human, it's clear that first
and second
will never be null because of the preceding (null, null)
pattern. However, Dart currently doesn't promote their types. I would like it to do so.
The lack of this feature particularly makes it harder to what @munificent describes as "a really common, important use case for patterns [of] doing "parallel" matching where you switch over an immediately-created record" in the presence of nullable types.
(Relatedly, it would also be nice if arg1
and arg2
were promoted to non-nullable after the switch
statement.)