authorgravatar for shawn@git.icuShawn Landden <shawn@git.icu> 2019-03-28 08:47:47-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-28 15:54:44-04:00
log66f13ba80787b652ee4f26669f4f2af99e1f1ea0
tree8733b7d4ac0a4dc4dc04081b3f26c3b9c141beed
parent85d188537538cdb7929ac05d7960d6b724676d7f

stage1: better error message when comparing against null

Closes: #2104

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

src/ir.cpp+2-1
......@@ -12210,7 +12210,8 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1221012210 return is_non_null;
1221112211 }
1221212212 } else if (op1->value.type->id == ZigTypeIdNull || op2->value.type->id == ZigTypeIdNull) {
12213 ir_add_error_node(ira, source_node, buf_sprintf("comparison against null can only be done with optionals"));
12213 ir_add_error_node(ira, source_node, buf_sprintf("only optionals (not '%s') can compare to null",
12214 buf_ptr(&(op1->value.type->id == ZigTypeIdNull ? op2->value.type->name : op1->value.type->name))));
1221412215 return ira->codegen->invalid_instruction;
1221512216 }
1221612217
test/compile_errors.zig+1-1
......@@ -839,7 +839,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
839839 \\ _ = &x == null;
840840 \\}
841841 ,
842 "tmp.zig:3:12: error: comparison against null can only be done with optionals",
842 "tmp.zig:3:12: error: only optionals (not '*i32') can compare to null",
843843 );
844844
845845 cases.add(