zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit a5c96c49d0eedbce40ad9a58d1b236f1eaeabd03 (tree)
parent 3f3003097cbf5a6ad9e0dfc29b2cafbe2e35dded
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun, 30 Oct 2022 16:27:02 -0700

langref: mention `void{}` and empty blocks

closes #11112
closes #12496

Diffstat:
Mdoc/langref.html.in | 24++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)

diff --git 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>