aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2019-09-13 09:29:35 +0200
committerAndrew Kelley <andrew@ziglang.org>2019-09-24 01:09:26 -0400
commit5fb7af26abbdf8f23007c2ccb4114e40ca0f450d (patch)
treeb77b5723938032486e01cb5f833a452a29b1d6c6 /test
parent93367adaa770944a13a8d44628dfefe1abe91906 (diff)
downloadzig-5fb7af26abbdf8f23007c2ccb4114e40ca0f450d.tar.gz
zig-5fb7af26abbdf8f23007c2ccb4114e40ca0f450d.zip
Fix result loc unwrapping with optional in error union
Fixes #2899
Diffstat (limited to 'test')
-rw-r--r--test/stage1/behavior/misc.zig12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/stage1/behavior/misc.zig b/test/stage1/behavior/misc.zig
index cffe1faebe..ab16b08be8 100644
--- a/test/stage1/behavior/misc.zig
+++ b/test/stage1/behavior/misc.zig
@@ -754,3 +754,15 @@ test "nested optional field in struct" {
};
expect(s.x.?.y == 127);
}
+
+fn maybe(x: bool) anyerror!?u32 {
+ return switch (x) {
+ true => u32(42),
+ else => null,
+ };
+}
+
+test "result location is optional inside error union" {
+ const x = maybe(true) catch unreachable;
+ expect(x.? == 42);
+}