From 02b4ea71e3a30d9076cd0c145777c792f2e4245b Mon Sep 17 00:00:00 2001 From: Evin Yulo Date: Sun, 11 Dec 2022 12:00:31 +0000 Subject: Improve tagged union documentation closes #13870 --- doc/langref.html.in | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'doc') 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#}.

- {#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#}

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, -- cgit v1.2.3