aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormartinhath <martinhath@users.noreply.github.com>2022-08-12 10:45:11 +0200
committerGitHub <noreply@github.com>2022-08-12 11:45:11 +0300
commit92568a0097a6aeb0cd59f1f3dae43d0ecd7a18d0 (patch)
tree7416433a436f7f0f92192377d182b7aea255d949 /src
parentfa50e179f7f8d523ff00be4cac90bf7659394140 (diff)
downloadzig-92568a0097a6aeb0cd59f1f3dae43d0ecd7a18d0.tar.gz
zig-92568a0097a6aeb0cd59f1f3dae43d0ecd7a18d0.zip
Sema: add error for signed integer division
stage1 error reads error: division with 'i32' and 'comptime_int': signed integers must use @divTrunc, @divFloor, or @divExact Fixes: #12339
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index f9b37f5b49..d697ab0a99 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -11261,7 +11261,12 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
try sema.addDivByZeroSafety(block, resolved_type, maybe_rhs_val, casted_rhs, is_int);
}
- const air_tag = if (is_int) Air.Inst.Tag.div_trunc else switch (block.float_mode) {
+ const air_tag = if (is_int) blk: {
+ if (lhs_ty.isSignedInt() or rhs_ty.isSignedInt()) {
+ 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()) });
+ }
+ break :blk Air.Inst.Tag.div_trunc;
+ } else switch (block.float_mode) {
.Optimized => Air.Inst.Tag.div_float_optimized,
.Strict => Air.Inst.Tag.div_float,
};