stage1: better error message when comparing against null

Closes: #2104
master
Shawn Landden 2019-03-28 08:47:47 -05:00 committed by Andrew Kelley
parent 85d1885375
commit 66f13ba807
2 changed files with 3 additions and 2 deletions

View File

@ -12210,7 +12210,8 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
return is_non_null;
}
} else if (op1->value.type->id == ZigTypeIdNull || op2->value.type->id == ZigTypeIdNull) {
ir_add_error_node(ira, source_node, buf_sprintf("comparison against null can only be done with optionals"));
ir_add_error_node(ira, source_node, buf_sprintf("only optionals (not '%s') can compare to null",
buf_ptr(&(op1->value.type->id == ZigTypeIdNull ? op2->value.type->name : op1->value.type->name))));
return ira->codegen->invalid_instruction;
}

View File

@ -839,7 +839,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ _ = &x == null;
\\}
,
"tmp.zig:3:12: error: comparison against null can only be done with optionals",
"tmp.zig:3:12: error: only optionals (not '*i32') can compare to null",
);
cases.add(