From ca70ca7e26aaae3425dad3a2b179f544bacf45e3 Mon Sep 17 00:00:00 2001 From: Timon Kruiper Date: Thu, 5 Sep 2019 18:43:54 +0200 Subject: Add compiler error when negating invalid type --- src/ir.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index eb65c1469e..2da8dea676 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -16565,6 +16565,15 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins if (type_is_invalid(expr_type)) return ira->codegen->invalid_instruction; + if (!(expr_type->id == ZigTypeIdInt || expr_type->id == ZigTypeIdComptimeInt || + expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat || + expr_type->id == ZigTypeIdVector)) + { + ir_add_error(ira, &instruction->base, + buf_sprintf("negation of type '%s'", buf_ptr(&expr_type->name))); + return ira->codegen->invalid_instruction; + } + bool is_wrap_op = (instruction->op_id == IrUnOpNegationWrap); ZigType *scalar_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type; -- cgit v1.2.3