Adding unwrapped error multiply regression test

This commit is contained in:
Mathieu Suen
2026-02-18 15:55:48 +01:00
committed by mlugg
parent 9ba9865e51
commit 7addae8f7d
+29
View File
@@ -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;