aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxackus <14938807+xackus@users.noreply.github.com>2019-10-27 21:35:22 +0100
committerxackus <14938807+xackus@users.noreply.github.com>2019-10-27 21:35:22 +0100
commit8960e8090e2c5a5f491e09baf8df65f52d0daf77 (patch)
treebc58e9efd1544d3888c7e98cd5fc5ecc3c797138
parenta0abd3be85a6c24a913ee650e1fd51bf3f457c68 (diff)
downloadzig-8960e8090e2c5a5f491e09baf8df65f52d0daf77.tar.gz
zig-8960e8090e2c5a5f491e09baf8df65f52d0daf77.zip
make implicit cast of tagged unions to enums easier to find in docs
-rw-r--r--doc/langref.html.in9
1 files changed, 9 insertions, 0 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in
index 618ea08cdb..3eb30c3058 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -2778,6 +2778,7 @@ test "simple union" {
This turns the union into a <em>tagged</em> 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#}
</p>
{#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#}
<p>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: