aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-06-21 14:06:01 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-06-21 14:06:01 -0400
commit48ccf427afa59fbcae969f3edd224b44eef153c9 (patch)
treec499e86431d5680804fd354d1dada6214c2fb1d2
parent4299cd4446f00ae68edd0c3b5273c83d38a6a253 (diff)
downloadzig-48ccf427afa59fbcae969f3edd224b44eef153c9.tar.gz
zig-48ccf427afa59fbcae969f3edd224b44eef153c9.zip
fix nested orelse and nested catch
-rw-r--r--src/ir.cpp4
-rw-r--r--test/stage1/behavior/error.zig22
-rw-r--r--test/stage1/behavior/optional.zig22
3 files changed, 46 insertions, 2 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 664d23040b..7b6f2dffe6 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -4065,7 +4065,7 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode
result_loc, is_comptime);
ir_set_cursor_at_end_and_append_block(irb, null_block);
- IrInstruction *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, lval,
+ IrInstruction *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, LValNone,
&peer_parent->peers.at(0)->base);
if (null_result == irb->codegen->invalid_instruction)
return irb->codegen->invalid_instruction;
@@ -7496,7 +7496,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
} else {
err_scope = parent_scope;
}
- IrInstruction *err_result = ir_gen_node_extra(irb, op2_node, err_scope, lval, &peer_parent->peers.at(0)->base);
+ IrInstruction *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base);
if (err_result == irb->codegen->invalid_instruction)
return irb->codegen->invalid_instruction;
IrBasicBlock *after_err_block = irb->current_basic_block;
diff --git a/test/stage1/behavior/error.zig b/test/stage1/behavior/error.zig
index babefba6f5..82ddc72b7b 100644
--- a/test/stage1/behavior/error.zig
+++ b/test/stage1/behavior/error.zig
@@ -335,3 +335,25 @@ test "debug info for optional error set" {
const SomeError = error{Hello};
var a_local_variable: ?SomeError = null;
}
+
+test "nested catch" {
+ const S = struct {
+ fn entry() void {
+ expectError(error.Bad, func());
+ }
+ fn fail() anyerror!Foo {
+ return error.Wrong;
+ }
+ fn func() anyerror!Foo {
+ const x = fail() catch
+ fail() catch
+ return error.Bad;
+ unreachable;
+ }
+ const Foo = struct {
+ field: i32,
+ };
+ };
+ S.entry();
+ comptime S.entry();
+}
diff --git a/test/stage1/behavior/optional.zig b/test/stage1/behavior/optional.zig
index b33e250383..ee3cb4aef9 100644
--- a/test/stage1/behavior/optional.zig
+++ b/test/stage1/behavior/optional.zig
@@ -78,3 +78,25 @@ test "unwrap function call with optional pointer return value" {
S.entry();
comptime S.entry();
}
+
+test "nested orelse" {
+ const S = struct {
+ fn entry() void {
+ expect(func() == null);
+ }
+ fn maybe() ?Foo {
+ return null;
+ }
+ fn func() ?Foo {
+ const x = maybe() orelse
+ maybe() orelse
+ return null;
+ unreachable;
+ }
+ const Foo = struct {
+ field: i32,
+ };
+ };
+ S.entry();
+ comptime S.entry();
+}