aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-03-28 12:23:19 +0300
committerAndrew Kelley <andrew@ziglang.org>2022-03-28 13:05:08 -0700
commita415fe0bc083159cf4bca6984636a564589e9789 (patch)
tree037e4548b04cbdde0eca8d07c3210a83fa1f4dec
parent3c4ac47e00d961186c8728df964a29a33275514c (diff)
downloadzig-a415fe0bc083159cf4bca6984636a564589e9789.tar.gz
zig-a415fe0bc083159cf4bca6984636a564589e9789.zip
AstGen: clear rl_ty_inst in setBreakResultLoc if one is not provided
-rw-r--r--src/AstGen.zig7
-rw-r--r--test/behavior/basic.zig21
2 files changed, 26 insertions, 2 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 4141b73e9a..f194270823 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -2731,6 +2731,7 @@ fn varDecl(
};
resolve_inferred_alloc = alloc;
init_scope.rl_ptr = alloc;
+ init_scope.rl_ty_inst = .none;
}
const init_result_loc: ResultLoc = .{ .block_ptr = &init_scope };
const init_inst = try reachableExpr(&init_scope, &init_scope.base, init_result_loc, var_decl.ast.init_node, node);
@@ -4860,7 +4861,7 @@ fn orelseCatchExpr(
// block_scope unstacked now, can add new instructions to parent_gz
try parent_gz.instructions.append(astgen.gpa, block);
- var then_scope = parent_gz.makeSubBlock(scope);
+ var then_scope = block_scope.makeSubBlock(scope);
defer then_scope.unstack();
// This could be a pointer or value depending on `unwrap_op`.
@@ -4870,7 +4871,7 @@ fn orelseCatchExpr(
else => try rvalue(&then_scope, block_scope.break_result_loc, unwrapped_payload, node),
};
- var else_scope = parent_gz.makeSubBlock(scope);
+ var else_scope = block_scope.makeSubBlock(scope);
defer else_scope.unstack();
var err_val_scope: Scope.LocalVal = undefined;
@@ -9850,10 +9851,12 @@ const GenZir = struct {
},
.discard, .none, .ptr, .ref => {
+ gz.rl_ty_inst = .none;
gz.break_result_loc = parent_rl;
},
.inferred_ptr => |ptr| {
+ gz.rl_ty_inst = .none;
gz.rl_ptr = ptr;
gz.break_result_loc = .{ .block_ptr = gz };
},
diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig
index e0e0f25569..6c21b8dd6c 100644
--- a/test/behavior/basic.zig
+++ b/test/behavior/basic.zig
@@ -854,3 +854,24 @@ test "labeled block implicitly ends in a break" {
if (a) break :blk;
}
}
+
+test "catch in block has correct result location" {
+ if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
+
+ const S = struct {
+ fn open() error{A}!@This() {
+ return @This(){};
+ }
+ fn foo(_: @This()) u32 {
+ return 1;
+ }
+ };
+ const config_h_text: u32 = blk: {
+ var dir = S.open() catch unreachable;
+ break :blk dir.foo();
+ };
+ try expect(config_h_text == 1);
+}