@@ -546,11 +546,18 @@ as explained below) and all declarations
546
546
introduce new identifiers into these scopes.
547
547
548
548
Identifiers are visible in
549
- the block they are defined in (including all sub-nodes and sub-blocks).
549
+ the block they are defined in (including all sub-nodes and sub-blocks):
550
+ Functions are visible in the whole block (even before their definitions) while
551
+ variables are only visible starting from the statement after the ``VariableDeclaration ``.
550
552
551
- As an exception, the scope of the "init" part of the or-loop
553
+ In particular,
554
+ variables cannot be referenced in the right hand side of their own variable
555
+ declaration.
556
+ Functions can be referenced already before their declaration (if they are visible).
557
+
558
+ As an exception to the general scoping rule, the scope of the "init" part of the for-loop
552
559
(the first block) extends across all other parts of the for loop.
553
- This means that variables declared in the init part (but not inside a
560
+ This means that variables (and functions) declared in the init part (but not inside a
554
561
block inside the init part) are visible in all other parts of the for-loop.
555
562
556
563
Identifiers declared in the other parts of the for loop respect the regular
@@ -559,21 +566,15 @@ syntactical scoping rules.
559
566
This means a for-loop of the form ``for { I... } C { P... } { B... } `` is equivalent
560
567
to ``{ I... for {} C { P... } { B... } } ``.
561
568
562
-
563
569
The parameters and return parameters of functions are visible in the
564
570
function body and their names have to be distinct.
565
571
566
- Variables can only be referenced after their declaration. In particular,
567
- variables cannot be referenced in the right hand side of their own variable
568
- declaration.
569
- Functions can be referenced already before their declaration (if they are visible).
572
+ Inside functions, it is not possible to reference a variable that was declared
573
+ outside of that function.
570
574
571
575
Shadowing is disallowed, i.e. you cannot declare an identifier at a point
572
576
where another identifier with the same name is also visible, even if it is
573
- not accessible.
574
-
575
- Inside functions, it is not possible to access a variable that was declared
576
- outside of that function.
577
+ not possible to reference it because it was declared outside the current function.
577
578
578
579
Formal Specification
579
580
--------------------
0 commit comments