Analyzer allows expression with type void
as expression switch case expression.
#52136
Labels
analyzer-language-patterns
Issues with analyzer's support for the patterns language feature
analyzer-spec
Issues with the analyzer's implementation of the language spec
area-analyzer
Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
P2
A bug or feature request we're likely to work on
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
See dart-lang/language#2907 (comment) for context.
Example:
The CFE gives the error:
That is correct, because expressions of type
void
are only allowed in specific positions, and the expression of an expression switch case isn't on the list.It didn't exist when the list was made, but we also haven't added the new position to that list.
The analyzer does not give the required error.
(We can choose to allow an expression switch case expression to have type
void
when the expression switch itself is allowed to have typevoid
. We can't just say that it's OK for the case expression to have typevoid
, because thatvoid
might get lost in a LUB with another branch's type. Unless a LUB containing at least onevoid
always ends up asvoid
. I don't know if it does, even when LUB'ed with, say,FutureOr<void>
.)The text was updated successfully, but these errors were encountered: