mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 12:59:04 +00:00
fix while continue block not checking for ignored expression
closes #957
This commit is contained in:
parent
01fb421031
commit
4a5cd0b895
12
src/ir.cpp
12
src/ir.cpp
@ -5462,8 +5462,10 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
|
||||
IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope);
|
||||
if (expr_result == irb->codegen->invalid_instruction)
|
||||
return expr_result;
|
||||
if (!instr_is_unreachable(expr_result))
|
||||
if (!instr_is_unreachable(expr_result)) {
|
||||
ir_mark_gen(ir_build_check_statement_is_void(irb, payload_scope, continue_expr_node, expr_result));
|
||||
ir_mark_gen(ir_build_br(irb, payload_scope, node, cond_block, is_comptime));
|
||||
}
|
||||
}
|
||||
|
||||
ir_set_cursor_at_end_and_append_block(irb, else_block);
|
||||
@ -5544,8 +5546,10 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
|
||||
IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, child_scope);
|
||||
if (expr_result == irb->codegen->invalid_instruction)
|
||||
return expr_result;
|
||||
if (!instr_is_unreachable(expr_result))
|
||||
if (!instr_is_unreachable(expr_result)) {
|
||||
ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, continue_expr_node, expr_result));
|
||||
ir_mark_gen(ir_build_br(irb, child_scope, node, cond_block, is_comptime));
|
||||
}
|
||||
}
|
||||
|
||||
IrInstruction *else_result = nullptr;
|
||||
@ -5609,8 +5613,10 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
|
||||
IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);
|
||||
if (expr_result == irb->codegen->invalid_instruction)
|
||||
return expr_result;
|
||||
if (!instr_is_unreachable(expr_result))
|
||||
if (!instr_is_unreachable(expr_result)) {
|
||||
ir_mark_gen(ir_build_check_statement_is_void(irb, scope, continue_expr_node, expr_result));
|
||||
ir_mark_gen(ir_build_br(irb, scope, node, cond_block, is_comptime));
|
||||
}
|
||||
}
|
||||
|
||||
IrInstruction *else_result = nullptr;
|
||||
|
||||
@ -2,6 +2,28 @@ const tests = @import("tests.zig");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
cases.add(
|
||||
"ignored expression in while continuation",
|
||||
\\export fn a() void {
|
||||
\\ while (true) : (bad()) {}
|
||||
\\}
|
||||
\\export fn b() void {
|
||||
\\ var x: anyerror!i32 = 1234;
|
||||
\\ while (x) |_| : (bad()) {} else |_| {}
|
||||
\\}
|
||||
\\export fn c() void {
|
||||
\\ var x: ?i32 = 1234;
|
||||
\\ while (x) |_| : (bad()) {}
|
||||
\\}
|
||||
\\fn bad() anyerror!void {
|
||||
\\ return error.Bad;
|
||||
\\}
|
||||
,
|
||||
"tmp.zig:2:24: error: expression value is ignored",
|
||||
"tmp.zig:6:25: error: expression value is ignored",
|
||||
"tmp.zig:10:25: error: expression value is ignored",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
"import outside package path",
|
||||
\\comptime{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user