Restriction of switch

This commit is contained in:
Alex Beregszaszi 2017-04-21 17:49:04 +01:00
parent 15ca987048
commit e9b08e029e

View File

@ -90,7 +90,7 @@ Grammar::
Switch = Switch =
'switch' Expression Case* ( 'default' ':' Block )? 'switch' Expression Case* ( 'default' ':' Block )?
Case = Case =
'case' Expression ':' Block 'case' Literal ':' Block
ForLoop = ForLoop =
'for' Block Expression Block Block 'for' Block Expression Block Block
BreakContinue = BreakContinue =
@ -120,6 +120,11 @@ the block they are defined in (including all sub-nodes and sub-blocks).
Shadowing is disallowed, i.e. you cannot declare an identifier at a point Shadowing is disallowed, i.e. you cannot declare an identifier at a point
where another identifier with the same name is also visible. where another identifier with the same name is also visible.
Switches must have at least one (or the default) and at most one default case.
If all possible values of the expression is covered, the default case should
not be allowed (i.e. a switch with a ``bool`` expression and having both a
true and false case should not allow a default case).
In for-loops, identifiers declared in the first block (the init block) In for-loops, identifiers declared in the first block (the init block)
are visible in all other parts of the for loop (but not outside of the loop). are visible in all other parts of the for loop (but not outside of the loop).
Identifiers declared in the other parts of the for loop respect the regular Identifiers declared in the other parts of the for loop respect the regular