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" {...@@ -2778,6 +2778,7 @@ test "simple union" {
2778 This turns the union into a <em>tagged</em> union, which makes it eligible2778 This turns the union into a <em>tagged</em> union, which makes it eligible
2779 to use with {#link|switch#} expressions. One can use {#link|@TagType#} to2779 to use with {#link|switch#} expressions. One can use {#link|@TagType#} to
2780 obtain the enum type from the union type.2780 obtain the enum type from the union type.
2781 Tagged unions implicitly cast to their enum {#link|Implicit Cast: unions and enums#}
2781 </p>2782 </p>
2782 {#code_begin|test#}2783 {#code_begin|test#}
2783const std = @import("std");2784const std = @import("std");
...@@ -2805,6 +2806,14 @@ test "switch on tagged union" {...@@ -2805,6 +2806,14 @@ test "switch on tagged union" {
2805test "@TagType" {2806test "@TagType" {
2806 assert(@TagType(ComplexType) == ComplexTypeTag);2807 assert(@TagType(ComplexType) == ComplexTypeTag);
2807}2808}
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}
2808 {#code_end#}2817 {#code_end#}
2809 <p>In order to modify the payload of a tagged union in a switch expression,2818 <p>In order to modify the payload of a tagged union in a switch expression,
2810 place a {#syntax#}*{#endsyntax#} before the variable name to make it a pointer:2819 place a {#syntax#}*{#endsyntax#} before the variable name to make it a pointer: