diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-08-16 16:17:56 +0300 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-08-17 14:09:42 -0700 |
| commit | 59b6483d63ca68f63c0b3758e80da918629ada2c (patch) | |
| tree | cde36ed0a1e6bf58fe3562eb7bbd38636bb17559 /src/Sema.zig | |
| parent | 07f64a2e13ab80acffba7f7bdd5d7c58df7893c0 (diff) | |
| download | zig-59b6483d63ca68f63c0b3758e80da918629ada2c.tar.gz zig-59b6483d63ca68f63c0b3758e80da918629ada2c.zip | |
add test
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index e5700a6fe4..29a53ebb2a 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -11202,18 +11202,17 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(block, lhs_src, casted_lhs); const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(block, rhs_src, casted_rhs); - if ((lhs_ty.tag() == .comptime_float and rhs_ty.tag() == .comptime_int) or - (lhs_ty.tag() == .comptime_int and rhs_ty.tag() == .comptime_float)) + if ((lhs_ty.zigTypeTag() == .ComptimeFloat and rhs_ty.zigTypeTag() == .ComptimeInt) or + (lhs_ty.zigTypeTag() == .ComptimeInt and rhs_ty.zigTypeTag() == .ComptimeFloat)) { // If it makes a difference whether we coerce to ints or floats before doing the division, error. // If lhs % rhs is 0, it doesn't matter. - var lhs_val = maybe_lhs_val orelse unreachable; - var rhs_val = maybe_rhs_val orelse unreachable; - var rem = lhs_val.floatRem(rhs_val, resolved_type, sema.arena, target) catch unreachable; - var float_rem = rem.toFloat(f32); - if (float_rem != 0.0) { - return sema.fail(block, src, "ambiguous coercion of division operands: '{s}' and '{s}': division has non-zero reminder: {d}", .{ - @tagName(lhs_ty.tag()), @tagName(rhs_ty.tag()), float_rem, + const lhs_val = maybe_lhs_val orelse unreachable; + const rhs_val = maybe_rhs_val orelse unreachable; + const rem = lhs_val.floatRem(rhs_val, resolved_type, sema.arena, target) catch unreachable; + if (rem.compareWithZero(.neq)) { + return sema.fail(block, src, "ambiguous coercion of division operands '{s}' and '{s}'; division has non-zero reminder '{}'", .{ + @tagName(lhs_ty.tag()), @tagName(rhs_ty.tag()), rem.fmtValue(resolved_type, sema.mod), }); } } |
