authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2019-10-27 21:35:22+01:00
committergravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2019-10-27 21:35:22+01:00
log8960e8090e2c5a5f491e09baf8df65f52d0daf77
treebc58e9efd1544d3888c7e98cd5fc5ecc3c797138
parenta0abd3be85a6c24a913ee650e1fd51bf3f457c68

make implicit cast of tagged unions to enums easier to find in docs


1 files changed, 9 insertions(+), 0 deletions(-)

doc/langref.html.in+9
......@@ -2778,6 +2778,7 @@ test "simple union" {
27782778 This turns the union into a <em>tagged</em> union, which makes it eligible
27792779 to use with {#link|switch#} expressions. One can use {#link|@TagType#} to
27802780 obtain the enum type from the union type.
2781 Tagged unions implicitly cast to their enum {#link|Implicit Cast: unions and enums#}
27812782 </p>
27822783 {#code_begin|test#}
27832784const std = @import("std");
......@@ -2805,6 +2806,14 @@ test "switch on tagged union" {
28052806test "@TagType" {
28062807 assert(@TagType(ComplexType) == ComplexTypeTag);
28072808}
2809
2810test "implicit cast to enum" {
2811 const c1 = ComplexType{ .Ok = 42 };
2812 const c2 = ComplexType.NotOk;
2813
2814 assert(c1 == .Ok);
2815 assert(c2 == .NotOk);
2816}
28082817 {#code_end#}
28092818 <p>In order to modify the payload of a tagged union in a switch expression,
28102819 place a {#syntax#}*{#endsyntax#} before the variable name to make it a pointer: