Flow analysis doesn't recognize that null check patterns always match a non-nullable type #52084
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
P2
A bug or feature request we're likely to work on
Flow analysis currently (as of cb4c9c7) fails to recognize that if the matched value type is non-nullable, then a null check pattern (e.g.
_?
) or the equivalent relational pattern (!= null
), will always match.As a result, flow analysis can't recognize that a switch statement like this one is trivially exhaustive:
And so an error is issued at (1), saying "The body might complete normally, causing 'null' to be returned, but the return type, 'bool', is a potentially non-nullable type."
If flow analysis were slightly smarter, it would see that no error needs to be issued at (1), because
var _?
always matches the non-nullable typeint
, so there would be no error.The text was updated successfully, but these errors were encountered: