commit 7addae8f7df4305d588c1583036d69a1ae08030c (tree)
parent 9ba9865e5191dcfdcf7ca794e3b26cbf5c6138bb
Author: Mathieu Suen <mathieusuen@yahoo.fr>
Date: Wed, 18 Feb 2026 15:55:48 +0100
Adding unwrapped error multiply regression test
Diffstat:
1 file changed, 29 insertions(+), 0 deletions(-)
diff --git a/test/behavior/math.zig b/test/behavior/math.zig
@@ -1073,6 +1073,35 @@ test "@mulWithOverflow bitsize > 32" {
try testMulWithOverflow(i63, minInt(i63), minInt(i63), 0, 1);
}
+fn captureMultiply(comptime T: type) type {
+ return struct {
+ opA: T,
+
+ fn returnA(self: @This()) anyerror!T {
+ return self.opA;
+ }
+
+ fn testMutiplyWithOverflow(self: @This(), comptime b: T, expected: T) !void {
+ const a = try self.returnA();
+
+ const c = a * b;
+ try expectEqual(expected, c);
+ }
+ };
+}
+
+test "Multiply unwrap error * immediate" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
+
+ try (captureMultiply(i8){ .opA = 3 }).testMutiplyWithOverflow(-1, -3);
+ try (captureMultiply(i16){ .opA = 3 }).testMutiplyWithOverflow(-1, -3);
+ try (captureMultiply(i32){ .opA = 3 }).testMutiplyWithOverflow(-1, -3);
+ try (captureMultiply(i64){ .opA = 3 }).testMutiplyWithOverflow(-1, -3);
+}
+
test "@mulWithOverflow bitsize 128 bits" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;