| author | |
| committer | |
| log | 92568a0097a6aeb0cd59f1f3dae43d0ecd7a18d0 |
| tree | 7416433a436f7f0f92192377d182b7aea255d949 |
| parent | fa50e179f7f8d523ff00be4cac90bf7659394140 |
| signature |
stage1 error reads
error: division with 'i32' and 'comptime_int': signed integers must use @divTrunc, @divFloor, or @divExact
Fixes: #123393 files changed, 15 insertions(+), 10 deletions(-)
src/Sema.zig+6-1| ... | ... | @@ -11261,7 +11261,12 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 11261 | 11261 | try sema.addDivByZeroSafety(block, resolved_type, maybe_rhs_val, casted_rhs, is_int); |
| 11262 | 11262 | } |
| 11263 | 11263 | |
| 11264 | const air_tag = if (is_int) Air.Inst.Tag.div_trunc else switch (block.float_mode) { | |
| 11264 | const air_tag = if (is_int) blk: { | |
| 11265 | if (lhs_ty.isSignedInt() or rhs_ty.isSignedInt()) { | |
| 11266 | return sema.fail(block, src, "division with '{s}' and '{s}': signed integers must use @divTrunc, @divFloor, or @divExact", .{ @tagName(lhs_ty.tag()), @tagName(rhs_ty.tag()) }); | |
| 11267 | } | |
| 11268 | break :blk Air.Inst.Tag.div_trunc; | |
| 11269 | } else switch (block.float_mode) { | |
| 11265 | 11270 | .Optimized => Air.Inst.Tag.div_float_optimized, |
| 11266 | 11271 | .Strict => Air.Inst.Tag.div_float, |
| 11267 | 11272 | }; |
test/cases/compile_errors/signed_integer_division.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | export fn foo(a: i32, b: i32) i32 { | |
| 2 | return a / b; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage2 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // :2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact |
test/cases/compile_errors/stage1/obj/signed_integer_division.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | export fn foo(a: i32, b: i32) i32 { | |
| 2 | return a / b; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage1 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact |