Only allow labels on composite statements. #1978
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
closed-as-intended
Closed as the reported issue is expected behavior
type-enhancement
A request for a change that isn't a bug
The grammar allows you to put labels on simple single statements (e.g., "foo:break foo;") where they don't make any sense.
There is really no reason for allowing them, except to make the grammar slightly smaller *but, IMO, the language less clear (Why can you write it? What does it do?).
I suggest introducing a syntactic category of composite statements which includes block-statements, loops, switches, trys and ifs (i.e., anything that may contain other statements), and then only allow labels on these (and on switch cases, ofcourse).
I.e.:
statement:
label* compositeStatement |
initializedVariableDeclaration ';' |
breakStatement |
continueStatement |
returnStatement |
throwStatement |
expressionStatement |
assertStatement |
functionSignature functionBody
;
compositeStatement:
block |
forStatement |
whileStatement |
doStatement |
switchStatement |
ifStatement |
tryStatement
;
The text was updated successfully, but these errors were encountered: