diff --git a/doc/langref.html.in b/doc/langref.html.in index 618ea08cd..3eb30c305 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -2778,6 +2778,7 @@ test "simple union" { This turns the union into a tagged union, which makes it eligible to use with {#link|switch#} expressions. One can use {#link|@TagType#} to obtain the enum type from the union type. + Tagged unions implicitly cast to their enum {#link|Implicit Cast: unions and enums#}

{#code_begin|test#} const std = @import("std"); @@ -2805,6 +2806,14 @@ test "switch on tagged union" { test "@TagType" { assert(@TagType(ComplexType) == ComplexTypeTag); } + +test "implicit cast to enum" { + const c1 = ComplexType{ .Ok = 42 }; + const c2 = ComplexType.NotOk; + + assert(c1 == .Ok); + assert(c2 == .NotOk); +} {#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: