mirror of
https://github.com/ziglang/zig.git
synced 2025-12-29 17:43:17 +00:00
langref: Expand "if error union with optional" test case
Follow-up to #5818, closes #5819
This commit is contained in:
parent
2064e84cdd
commit
12a7dedb1f
@ -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#}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user