From 12a7dedb1f1ce34b16993d33aa97d7b78d5d5ca2 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Wed, 8 Jul 2020 13:40:16 -0700 Subject: [PATCH] langref: Expand "if error union with optional" test case Follow-up to #5818, closes #5819 --- doc/langref.html.in | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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#}