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...@@ -7624,26 +7624,27 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
7624 is_comptime);7624 is_comptime);
76257625
7626 ir_set_cursor_at_end_and_append_block(irb, err_block);7626 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);
7627 Scope *err_scope;7628 Scope *err_scope;
7628 if (var_node) {7629 if (var_node) {
7629 assert(var_node->type == NodeTypeSymbol);7630 assert(var_node->type == NodeTypeSymbol);
7630 Buf *var_name = var_node->data.symbol_expr.symbol;7631 Buf *var_name = var_node->data.symbol_expr.symbol;
7631 bool is_const = true;7632 bool is_const = true;
7632 bool is_shadowable = false;7633 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,
7634 is_const, is_const, is_shadowable, is_comptime);7635 is_const, is_const, is_shadowable, is_comptime);
7635 err_scope = var->child_scope;7636 err_scope = var->child_scope;
7636 IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr);7637 IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr);
7637 ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_ptr);7638 ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_ptr);
7638 } else {7639 } else {
7639 err_scope = parent_scope;7640 err_scope = subexpr_scope;
7640 }7641 }
7641 IrInstruction *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base);7642 IrInstruction *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base);
7642 if (err_result == irb->codegen->invalid_instruction)7643 if (err_result == irb->codegen->invalid_instruction)
7643 return irb->codegen->invalid_instruction;7644 return irb->codegen->invalid_instruction;
7644 IrBasicBlock *after_err_block = irb->current_basic_block;7645 IrBasicBlock *after_err_block = irb->current_basic_block;
7645 if (!instr_is_unreachable(err_result))7646 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
7648 ir_set_cursor_at_end_and_append_block(irb, ok_block);7649 ir_set_cursor_at_end_and_append_block(irb, ok_block);
7649 IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, parent_scope, node, err_union_ptr, false, false);7650 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 {...@@ -1148,6 +1148,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1148 "tmp.zig:4:5: error: no-inline call of inline function",1148 "tmp.zig:4:5: error: no-inline call of inline function",
1149 );1149 );
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
1151 cases.add(1167 cases.add(
1152 "comptime continue inside runtime switch",1168 "comptime continue inside runtime switch",
1153 \\export fn entry() void {1169 \\export fn entry() void {