| author | |
| committer | |
| log | d065f297ab6de5ca35636d169195ce5da6235786 |
| tree | d71cba76897f46dd77e0e83dd98ad500bc156be3 |
| parent | 6b10f03b4a868cc02fc0535193ea0108c77ddd1f |
closes #24602 files changed, 20 insertions(+), 1 deletions(-)
src/ir.cpp+3-1| ... | ... | @@ -5808,8 +5808,10 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5808 | 5808 | |
| 5809 | 5809 | IrInstruction *body_result = ir_gen_node(irb, body_node, &loop_scope->base); |
| 5810 | 5810 | |
| 5811 | if (!instr_is_unreachable(body_result)) | |
| 5811 | if (!instr_is_unreachable(body_result)) { | |
| 5812 | ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.for_expr.body, body_result)); | |
| 5812 | 5813 | ir_mark_gen(ir_build_br(irb, child_scope, node, continue_block, is_comptime)); |
| 5814 | } | |
| 5813 | 5815 | |
| 5814 | 5816 | ir_set_cursor_at_end_and_append_block(irb, continue_block); |
| 5815 | 5817 | IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false); |
test/compile_errors.zig+17| ... | ... | @@ -5918,4 +5918,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5918 | 5918 | , |
| 5919 | 5919 | "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'", |
| 5920 | 5920 | ); |
| 5921 | ||
| 5922 | cases.add( | |
| 5923 | "for loop body expression ignored", | |
| 5924 | \\fn returns() usize { | |
| 5925 | \\ return 2; | |
| 5926 | \\} | |
| 5927 | \\export fn f1() void { | |
| 5928 | \\ for ("hello") |_| returns(); | |
| 5929 | \\} | |
| 5930 | \\export fn f2() void { | |
| 5931 | \\ var x: anyerror!i32 = error.Bad; | |
| 5932 | \\ for ("hello") |_| returns() else unreachable; | |
| 5933 | \\} | |
| 5934 | , | |
| 5935 | "tmp.zig:5:30: error: expression value is ignored", | |
| 5936 | "tmp.zig:9:30: error: expression value is ignored", | |
| 5937 | ); | |
| 5921 | 5938 | } |