| author | |
| committer | |
| log | ca70ca7e26aaae3425dad3a2b179f544bacf45e3 |
| tree | c6b76b2254093eaa68837c0e0825e49623dbd6ab |
| parent | 4a5bc89862aca6f1870cbaa7d398ab2eed3022c3 |
2 files changed, 22 insertions(+), 0 deletions(-)
src/ir.cpp+9| ... | ... | @@ -16565,6 +16565,15 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins |
| 16565 | 16565 | if (type_is_invalid(expr_type)) |
| 16566 | 16566 | return ira->codegen->invalid_instruction; |
| 16567 | 16567 | |
| 16568 | if (!(expr_type->id == ZigTypeIdInt || expr_type->id == ZigTypeIdComptimeInt || | |
| 16569 | expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat || | |
| 16570 | expr_type->id == ZigTypeIdVector)) | |
| 16571 | { | |
| 16572 | ir_add_error(ira, &instruction->base, | |
| 16573 | buf_sprintf("negation of type '%s'", buf_ptr(&expr_type->name))); | |
| 16574 | return ira->codegen->invalid_instruction; | |
| 16575 | } | |
| 16576 | ||
| 16568 | 16577 | bool is_wrap_op = (instruction->op_id == IrUnOpNegationWrap); |
| 16569 | 16578 | |
| 16570 | 16579 | ZigType *scalar_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type; |
test/compile_errors.zig+13| ... | ... | @@ -2,6 +2,19 @@ const tests = @import("tests.zig"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | 3 | |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add( | |
| 6 | "attempt to negate a non-integer, non-float or non-vector type", | |
| 7 | \\fn foo() anyerror!u32 { | |
| 8 | \\ return 1; | |
| 9 | \\} | |
| 10 | \\ | |
| 11 | \\export fn entry() void { | |
| 12 | \\ const x = -foo(); | |
| 13 | \\} | |
| 14 | , | |
| 15 | "tmp.zig:6:15: error: negation of type 'anyerror!u32'", | |
| 16 | ); | |
| 17 | ||
| 5 | 18 | cases.add( |
| 6 | 19 | "attempt to create 17 bit float type", |
| 7 | 20 | \\const builtin = @import("builtin"); |