diff options
| author | Evin Yulo <yujiri@disroot.org> | 2022-12-11 12:00:31 +0000 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-12-13 15:11:43 -0500 |
| commit | 02b4ea71e3a30d9076cd0c145777c792f2e4245b (patch) | |
| tree | 3811def50f0de121e3cb8cad9d1c0965f0869c43 /doc | |
| parent | 35c6fe665c7f3f8ba14aaee97c832000cbf5ddc2 (diff) | |
| download | zig-02b4ea71e3a30d9076cd0c145777c792f2e4245b.tar.gz zig-02b4ea71e3a30d9076cd0c145777c792f2e4245b.zip | |
Improve tagged union documentation
closes #13870
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/langref.html.in | 11 |
1 files changed, 1 insertions, 10 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in index eb89b3d2a2..4ff1504627 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -3824,7 +3824,7 @@ test "simple union" { to use with {#link|switch#} expressions. Tagged unions coerce to their tag type: {#link|Type Coercion: unions and enums#}. </p> - {#code_begin|test|test_switch_tagged_union#} + {#code_begin|test|test_tagged_union#} const std = @import("std"); const expect = std.testing.expect; @@ -3850,14 +3850,6 @@ test "switch on tagged union" { test "get tag type" { try expect(std.meta.Tag(ComplexType) == ComplexTypeTag); } - -test "coerce to enum" { - const c1 = ComplexType{ .ok = 42 }; - const c2 = ComplexType.not_ok; - - try expect(c1 == .ok); - try expect(c2 == .not_ok); -} {#code_end#} <p>In order to modify the payload of a tagged union in a switch expression, place a {#syntax#}*{#endsyntax#} before the variable name to make it a pointer: @@ -3877,7 +3869,6 @@ const ComplexType = union(ComplexTypeTag) { test "modify tagged union in switch" { var c = ComplexType{ .ok = 42 }; - try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok); switch (c) { ComplexTypeTag.ok => |*value| value.* += 1, |
