diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-10-30 16:27:02 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-10-30 16:33:22 -0700 |
| commit | a5c96c49d0eedbce40ad9a58d1b236f1eaeabd03 (patch) | |
| tree | ed9cfb13cc4d9aba92b8494c6c53a82e938099e3 /doc/langref.html.in | |
| parent | 3f3003097cbf5a6ad9e0dfc29b2cafbe2e35dded (diff) | |
| download | zig-a5c96c49d0eedbce40ad9a58d1b236f1eaeabd03.tar.gz zig-a5c96c49d0eedbce40ad9a58d1b236f1eaeabd03.zip | |
langref: mention `void{}` and empty blocks
closes #11112
closes #12496
Diffstat (limited to 'doc/langref.html.in')
| -rw-r--r-- | doc/langref.html.in | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in index 5da2697187..7cf3631aa5 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -760,7 +760,7 @@ pub fn main() void { <tr> <th scope="row">{#syntax#}void{#endsyntax#}</th> <td>(none)</td> - <td>0 bit type</td> + <td>Always the value {#syntax#}void{}{#endsyntax#}</td> </tr> <tr> <th scope="row">{#syntax#}noreturn{#endsyntax#}</th> @@ -1061,7 +1061,7 @@ fn addOne(number: i32) i32 { <p> Test declarations contain the {#link|keyword|Keyword Reference#} {#syntax#}test{#endsyntax#}, followed by an optional name written as a {#link|string literal|String Literals and Unicode Code Point Literals#}, followed - by a {#link|block|blocks#} containing any valid Zig code that is allowed in a {#link|function|Functions#}. + by a {#link|block|Blocks#} containing any valid Zig code that is allowed in a {#link|function|Functions#}. </p> <aside> 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" { {#code_end#} {#header_close#} - {#header_open|blocks#} + {#header_open|Blocks#} <p> Blocks are used to limit the scope of variable declarations: </p> @@ -4088,6 +4088,22 @@ test "separate scopes" { } {#code_end#} {#header_close#} + + {#header_open|Empty Blocks#} + <p>An empty block is equivalent to {#syntax#}void{}{#endsyntax#}:</p> + {#code_begin|test|empty_block#} +const std = @import("std"); +const expect = std.testing.expect; + +test { + const a = {}; + const b = void{}; + try expect(@TypeOf(a) == void); + try expect(@TypeOf(b) == void); + try expect(a == b); +} + {#code_end#} + {#header_close#} {#header_close#} {#header_open|switch#} @@ -11987,7 +12003,7 @@ fn readU32Be() u32 {} {#syntax#}break{#endsyntax#} can be used with a block label to return a value from the block. It can also be used to exit a loop before iteration completes naturally. <ul> - <li>See also {#link|blocks#}, {#link|while#}, {#link|for#}</li> + <li>See also {#link|Blocks#}, {#link|while#}, {#link|for#}</li> </ul> </td> </tr> |
