Non-optimal recovery and error message for case
in switch expression.
#51886
Labels
front-end-fasta
legacy-area-front-end
Legacy: Use area-dart-model instead.
type-enhancement
A request for a change that isn't a bug
I wrote the "obvious"
and got the non-obvious error message:
That's not the most actionable error message. We could assume that the user thought
case
was needed for switch expressions (or forgot removing it when switching from switch statement to switch expression), and tell them to remove thecase
.In general, switch expressions differ from switch statements. We should recognize switch statements syntax in switch expressions, and suggest changing it to the correct syntax.
gives the following errors:
(And the switch being non-exhaustive on top, a derived error which should probably be suppressed if you cannot parse the cases.)
I'd prefer an error message like:
This would tell me what to change, and recover from finding
:
and;
where=>
and,
are expected.Maybe it also applies the other direction, using switch expression syntax in a switch statement:
yields the errors:
which isn't particularly enlightening (the "expected to find
case
" is correct, the recovery isn't great).After adding just the
case
keywords, I get:That suggests using
;
instead of,
, but the=>
is just misunderstood somehow.The text was updated successfully, but these errors were encountered: