authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2020-07-08 13:40:16-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-09 03:30:35+00:00
log12a7dedb1f1ce34b16993d33aa97d7b78d5d5ca2
treee909f1e527e5a084c53a971a7b1dc1b40ae6b889
parent2064e84cdd596b5bc63c8d3e7e5aa4130221faee

langref: Expand "if error union with optional" test case

Follow-up to #5818, closes #5819

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

doc/langref.html.in+16
...@@ -3886,6 +3886,22 @@ test "if error union with optional" {...@@ -3886,6 +3886,22 @@ test "if error union with optional" {
3886 } else |err| {3886 } else |err| {
3887 assert(err == error.BadValue);3887 assert(err == error.BadValue);
3888 }3888 }
3889
3890 // Access the value by reference by using a pointer capture each time.
3891 var d: anyerror!?u32 = 3;
3892 if (d) |*optional_value| {
3893 if (optional_value.*) |*value| {
3894 value.* = 9;
3895 }
3896 } else |err| {
3897 unreachable;
3898 }
3899
3900 if (d) |optional_value| {
3901 assert(optional_value.? == 9);
3902 } else |err| {
3903 unreachable;
3904 }
3889}3905}
3890 {#code_end#}3906 {#code_end#}
3891 {#see_also|Optionals|Errors#}3907 {#see_also|Optionals|Errors#}