authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-02 21:14:42-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-02 21:14:42-04:00
log9daf0140e5a78802fd294bce8a9019f59bd89b61
treecc05187cfb5cf5fa59e12f9fdab6c6d31a56ac3e
parentb84ff1dd325b14bc4a6fc37109b5af8203e6a517
signaturelock-open Commit is signed but in an unrecognized format.

add missing compile error for comptime continue inside runtime catch

See #2604

2 files changed, 20 insertions(+), 3 deletions(-)

src/ir.cpp+4-3
......@@ -7624,26 +7624,27 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
76247624 is_comptime);
76257625
76267626 ir_set_cursor_at_end_and_append_block(irb, err_block);
7627 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, parent_scope, is_comptime);
76277628 Scope *err_scope;
76287629 if (var_node) {
76297630 assert(var_node->type == NodeTypeSymbol);
76307631 Buf *var_name = var_node->data.symbol_expr.symbol;
76317632 bool is_const = true;
76327633 bool is_shadowable = false;
7633 ZigVar *var = ir_create_var(irb, node, parent_scope, var_name,
7634 ZigVar *var = ir_create_var(irb, node, subexpr_scope, var_name,
76347635 is_const, is_const, is_shadowable, is_comptime);
76357636 err_scope = var->child_scope;
76367637 IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr);
76377638 ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_ptr);
76387639 } else {
7639 err_scope = parent_scope;
7640 err_scope = subexpr_scope;
76407641 }
76417642 IrInstruction *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base);
76427643 if (err_result == irb->codegen->invalid_instruction)
76437644 return irb->codegen->invalid_instruction;
76447645 IrBasicBlock *after_err_block = irb->current_basic_block;
76457646 if (!instr_is_unreachable(err_result))
7646 ir_mark_gen(ir_build_br(irb, err_scope, node, end_block, is_comptime));
7647 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));
76477648
76487649 ir_set_cursor_at_end_and_append_block(irb, ok_block);
76497650 IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, parent_scope, node, err_union_ptr, false, false);
test/compile_errors.zig+16
......@@ -1148,6 +1148,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
11481148 "tmp.zig:4:5: error: no-inline call of inline function",
11491149 );
11501150
1151 cases.add(
1152 "comptime continue inside runtime catch",
1153 \\export fn entry(c: bool) void {
1154 \\ const ints = [_]u8{ 1, 2 };
1155 \\ inline for (ints) |_| {
1156 \\ bad() catch |_| continue;
1157 \\ }
1158 \\}
1159 \\fn bad() !void {
1160 \\ return error.Bad;
1161 \\}
1162 ,
1163 "tmp.zig:4:25: error: comptime control flow inside runtime block",
1164 "tmp.zig:4:15: note: runtime block created here",
1165 );
1166
11511167 cases.add(
11521168 "comptime continue inside runtime switch",
11531169 \\export fn entry() void {