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

Follow-up to #5818, closes #5819
This commit is contained in:
Ryan Liptak 2020-07-08 13:40:16 -07:00 committed by Andrew Kelley
parent 2064e84cdd
commit 12a7dedb1f

View File

@ -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#}