From e9b08e029eb48fff9cd3b3287a88e1282395bfb4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 21 Apr 2017 17:49:04 +0100 Subject: [PATCH] Restriction of switch --- docs/julia.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/julia.rst b/docs/julia.rst index 5d6b84976..7740bc706 100644 --- a/docs/julia.rst +++ b/docs/julia.rst @@ -90,7 +90,7 @@ Grammar:: Switch = 'switch' Expression Case* ( 'default' ':' Block )? Case = - 'case' Expression ':' Block + 'case' Literal ':' Block ForLoop = 'for' Block Expression Block Block 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 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) 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