aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-02-18 17:49:26 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-02-18 17:49:26 -0500
commit043090020f5052fdee0fffc02dc7ef379ea63fd0 (patch)
tree1807151c282732b02adfb6c0aa0e7ef248f74859
parent8922008dec5d631da0305527f670fb34852dfee7 (diff)
downloadzig-043090020f5052fdee0fffc02dc7ef379ea63fd0.tar.gz
zig-043090020f5052fdee0fffc02dc7ef379ea63fd0.zip
docs: shadowing
closes #1245
-rw-r--r--doc/langref.html.in29
1 files changed, 29 insertions, 0 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in
index 03afa1cf09..34cae7282d 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -2377,7 +2377,36 @@ test "labeled break from labeled block expression" {
{#code_end#}
<p>Here, {#syntax#}blk{#endsyntax#} can be any name.</p>
{#see_also|Labeled while|Labeled for#}
+
+ {#header_open|Shadowing#}
+ <p>It is never allowed for an identifier to "hide" another one by using the same name:</p>
+ {#code_begin|test_err|redefinition#}
+const pi = 3.14;
+
+test "inside test block" {
+ // Let's even go inside another block
+ {
+ var pi: i32 = 1234;
+ }
+}
+ {#code_end#}
+ <p>
+ Because of this, when you read Zig code you can rely on an identifier always meaning the same thing,
+ within the scope it is defined. Note that you can, however use the same name if the scopes are separate:
+ </p>
+ {#code_begin|test#}
+test "separate scopes" {
+ {
+ const pi = 3.14;
+ }
+ {
+ var pi: bool = true;
+ }
+}
+ {#code_end#}
{#header_close#}
+ {#header_close#}
+
{#header_open|switch#}
{#code_begin|test|switch#}
const assert = @import("std").debug.assert;