| author | |
| committer | |
| log | c96131f30caaf6d7cd1d202891a28ee0df8b577e |
| tree | db1f02cdbc1955ef07b523c4c7ba0acb69476127 |
| parent | c4770e7aa54a7a88eacf9e7780b0fe860f29251f |
Closes #38192 files changed, 11 insertions(+), 0 deletions(-)
src/ir.cpp+2| ... | ... | @@ -7456,6 +7456,8 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 7456 | 7456 | // it's actually in break statements, handled similarly to return statements. |
| 7457 | 7457 | // That is why we set those values in loop_scope above and not in this ir_gen_node call. |
| 7458 | 7458 | IrInstruction *body_result = ir_gen_node(irb, body_node, &loop_scope->base); |
| 7459 | if (body_result == irb->codegen->invalid_instruction) | |
| 7460 | return irb->codegen->invalid_instruction; | |
| 7459 | 7461 | |
| 7460 | 7462 | if (!instr_is_unreachable(body_result)) { |
| 7461 | 7463 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.for_expr.body, body_result)); |
test/compile_errors.zig+9| ... | ... | @@ -2,6 +2,15 @@ const tests = @import("tests.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.addTest("errors in for loop bodies are propagated", | |
| 6 | \\pub export fn entry() void { | |
| 7 | \\ var arr: [100]u8 = undefined; | |
| 8 | \\ for (arr) |bits| _ = @popCount(bits); | |
| 9 | \\} | |
| 10 | , &[_][]const u8{ | |
| 11 | "tmp.zig:3:26: error: expected 2 arguments, found 1", | |
| 12 | }); | |
| 13 | ||
| 5 | 14 | cases.addTest("error in struct initializer doesn't crash the compiler", |
| 6 | 15 | \\pub export fn entry() void { |
| 7 | 16 | \\ const bitfield = struct { |