aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorRyan Liptak <squeek502@hotmail.com>2020-07-08 13:40:16 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-07-09 03:30:35 +0000
commit12a7dedb1f1ce34b16993d33aa97d7b78d5d5ca2 (patch)
treee909f1e527e5a084c53a971a7b1dc1b40ae6b889 /doc
parent2064e84cdd596b5bc63c8d3e7e5aa4130221faee (diff)
downloadzig-12a7dedb1f1ce34b16993d33aa97d7b78d5d5ca2.tar.gz
zig-12a7dedb1f1ce34b16993d33aa97d7b78d5d5ca2.zip
langref: Expand "if error union with optional" test case
Follow-up to #5818, closes #5819
Diffstat (limited to 'doc')
-rw-r--r--doc/langref.html.in16
1 files changed, 16 insertions, 0 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in
index 78dcd537b8..f64170817f 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -3886,6 +3886,22 @@ test "if error union with optional" {
} else |err| {
assert(err == error.BadValue);
}
+
+ // Access the value by reference by using a pointer capture each time.
+ var d: anyerror!?u32 = 3;
+ if (d) |*optional_value| {
+ if (optional_value.*) |*value| {
+ value.* = 9;
+ }
+ } else |err| {
+ unreachable;
+ }
+
+ if (d) |optional_value| {
+ assert(optional_value.? == 9);
+ } else |err| {
+ unreachable;
+ }
}
{#code_end#}
{#see_also|Optionals|Errors#}