| ... | @@ -3824,7 +3824,7 @@ test "simple union" { | ... | @@ -3824,7 +3824,7 @@ test "simple union" { |
| 3824 | to use with {#link|switch#} expressions. | 3824 | to use with {#link|switch#} expressions. |
| 3825 | Tagged unions coerce to their tag type: {#link|Type Coercion: unions and enums#}. | 3825 | Tagged unions coerce to their tag type: {#link|Type Coercion: unions and enums#}. |
| 3826 | </p> | 3826 | </p> |
| 3827 | {#code_begin|test|test_switch_tagged_union#} | 3827 | {#code_begin|test|test_tagged_union#} |
| 3828 | const std = @import("std"); | 3828 | const std = @import("std"); |
| 3829 | const expect = std.testing.expect; | 3829 | const expect = std.testing.expect; |
| 3830 | | 3830 | |
| ... | @@ -3850,14 +3850,6 @@ test "switch on tagged union" { | ... | @@ -3850,14 +3850,6 @@ test "switch on tagged union" { |
| 3850 | test "get tag type" { | 3850 | test "get tag type" { |
| 3851 | try expect(std.meta.Tag(ComplexType) == ComplexTypeTag); | 3851 | try expect(std.meta.Tag(ComplexType) == ComplexTypeTag); |
| 3852 | } | 3852 | } |
| 3853 | | | |
| 3854 | test "coerce to enum" { | | |
| 3855 | const c1 = ComplexType{ .ok = 42 }; | | |
| 3856 | const c2 = ComplexType.not_ok; | | |
| 3857 | | | |
| 3858 | try expect(c1 == .ok); | | |
| 3859 | try expect(c2 == .not_ok); | | |
| 3860 | } | | |
| 3861 | {#code_end#} | 3853 | {#code_end#} |
| 3862 | <p>In order to modify the payload of a tagged union in a switch expression, | 3854 | <p>In order to modify the payload of a tagged union in a switch expression, |
| 3863 | place a {#syntax#}*{#endsyntax#} before the variable name to make it a pointer: | 3855 | place a {#syntax#}*{#endsyntax#} before the variable name to make it a pointer: |
| ... | @@ -3877,7 +3869,6 @@ const ComplexType = union(ComplexTypeTag) { | ... | @@ -3877,7 +3869,6 @@ const ComplexType = union(ComplexTypeTag) { |
| 3877 | | 3869 | |
| 3878 | test "modify tagged union in switch" { | 3870 | test "modify tagged union in switch" { |
| 3879 | var c = ComplexType{ .ok = 42 }; | 3871 | var c = ComplexType{ .ok = 42 }; |
| 3880 | try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok); | | |
| 3881 | | 3872 | |
| 3882 | switch (c) { | 3873 | switch (c) { |
| 3883 | ComplexTypeTag.ok => |*value| value.* += 1, | 3874 | ComplexTypeTag.ok => |*value| value.* += 1, |