aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorTimon Kruiper <timonkruiper@gmail.com>2019-09-05 18:43:54 +0200
committerAndrew Kelley <andrew@ziglang.org>2019-09-05 15:27:50 -0400
commitca70ca7e26aaae3425dad3a2b179f544bacf45e3 (patch)
treec6b76b2254093eaa68837c0e0825e49623dbd6ab /src/ir.cpp
parent4a5bc89862aca6f1870cbaa7d398ab2eed3022c3 (diff)
downloadzig-ca70ca7e26aaae3425dad3a2b179f544bacf45e3.tar.gz
zig-ca70ca7e26aaae3425dad3a2b179f544bacf45e3.zip
Add compiler error when negating invalid type
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp9
1 files changed, 9 insertions, 0 deletions
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;