Inconsistent switch promotion. #60496
Labels
area-dart-model
For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.
model-flow
Implementation of flow analysis in analyzer/cfe
Example:
When run, this prints
Future<int>?
andFuture<int>
. The promotion in the switch depends on whether the last catch-all clause has a variable name or not, even if the variable name is never referenced. That's probably not intended.The second result is the best result, after having rejected
null
andint
, aFutureOr<int>?
can be concluded to be aFuture<int>
.If I switch the first two cases, the result changes to
FutureOr<int>
andFuture<int>
, so it's like the promotion from failing the first case gets lost when going from case 2 to case 3.Probably some optimization going wrong, maybe overly optimistically thinking that a pattern that doesn't reference
o
can't affect its type. (But that should be the matched value type before the pattern is applied, so probably something more than that.)@stereotype441
The text was updated successfully, but these errors were encountered: