authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-30 16:27:02-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-10-30 16:33:22-07:00
loga5c96c49d0eedbce40ad9a58d1b236f1eaeabd03
treeed9cfb13cc4d9aba92b8494c6c53a82e938099e3
parent3f3003097cbf5a6ad9e0dfc29b2cafbe2e35dded

langref: mention `void{}` and empty blocks

closes #11112 closes #12496

1 files changed, 20 insertions(+), 4 deletions(-)

doc/langref.html.in+20-4
......@@ -760,7 +760,7 @@ pub fn main() void {
760760 <tr>
761761 <th scope="row">{#syntax#}void{#endsyntax#}</th>
762762 <td>(none)</td>
763 <td>0 bit type</td>
763 <td>Always the value {#syntax#}void{}{#endsyntax#}</td>
764764 </tr>
765765 <tr>
766766 <th scope="row">{#syntax#}noreturn{#endsyntax#}</th>
......@@ -1061,7 +1061,7 @@ fn addOne(number: i32) i32 {
10611061 <p>
10621062 Test declarations contain the {#link|keyword|Keyword Reference#} {#syntax#}test{#endsyntax#}, followed by an
10631063 optional name written as a {#link|string literal|String Literals and Unicode Code Point Literals#}, followed
1064 by a {#link|block|blocks#} containing any valid Zig code that is allowed in a {#link|function|Functions#}.
1064 by a {#link|block|Blocks#} containing any valid Zig code that is allowed in a {#link|function|Functions#}.
10651065 </p>
10661066 <aside>
10671067 By convention, non-named tests should only be used to {#link|make other tests run|Nested Container Tests#}.
......@@ -4024,7 +4024,7 @@ test "call foo" {
40244024 {#code_end#}
40254025 {#header_close#}
40264026
4027 {#header_open|blocks#}
4027 {#header_open|Blocks#}
40284028 <p>
40294029 Blocks are used to limit the scope of variable declarations:
40304030 </p>
......@@ -4088,6 +4088,22 @@ test "separate scopes" {
40884088}
40894089 {#code_end#}
40904090 {#header_close#}
4091
4092 {#header_open|Empty Blocks#}
4093 <p>An empty block is equivalent to {#syntax#}void{}{#endsyntax#}:</p>
4094 {#code_begin|test|empty_block#}
4095const std = @import("std");
4096const expect = std.testing.expect;
4097
4098test {
4099 const a = {};
4100 const b = void{};
4101 try expect(@TypeOf(a) == void);
4102 try expect(@TypeOf(b) == void);
4103 try expect(a == b);
4104}
4105 {#code_end#}
4106 {#header_close#}
40914107 {#header_close#}
40924108
40934109 {#header_open|switch#}
......@@ -11987,7 +12003,7 @@ fn readU32Be() u32 {}
1198712003 {#syntax#}break{#endsyntax#} can be used with a block label to return a value from the block.
1198812004 It can also be used to exit a loop before iteration completes naturally.
1198912005 <ul>
11990 <li>See also {#link|blocks#}, {#link|while#}, {#link|for#}</li>
12006 <li>See also {#link|Blocks#}, {#link|while#}, {#link|for#}</li>
1199112007 </ul>
1199212008 </td>
1199312009 </tr>