authorgravatar for mathieusuen@yahoo.frMathieu Suen <mathieusuen@yahoo.fr> 2026-02-18 15:55:48+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-04-10 23:23:33+02:00
log7addae8f7df4305d588c1583036d69a1ae08030c
treece167b671dbae2bdbd295a43aba6d1201a193d4c
parent9ba9865e5191dcfdcf7ca794e3b26cbf5c6138bb

Adding unwrapped error multiply regression test


1 files changed, 29 insertions(+), 0 deletions(-)

test/behavior/math.zig+29
......@@ -1073,6 +1073,35 @@ test "@mulWithOverflow bitsize > 32" {
10731073 try testMulWithOverflow(i63, minInt(i63), minInt(i63), 0, 1);
10741074}
10751075
1076fn captureMultiply(comptime T: type) type {
1077 return struct {
1078 opA: T,
1079
1080 fn returnA(self: @This()) anyerror!T {
1081 return self.opA;
1082 }
1083
1084 fn testMutiplyWithOverflow(self: @This(), comptime b: T, expected: T) !void {
1085 const a = try self.returnA();
1086
1087 const c = a * b;
1088 try expectEqual(expected, c);
1089 }
1090 };
1091}
1092
1093test "Multiply unwrap error * immediate" {
1094 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
1095 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
1096 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1097 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
1098
1099 try (captureMultiply(i8){ .opA = 3 }).testMutiplyWithOverflow(-1, -3);
1100 try (captureMultiply(i16){ .opA = 3 }).testMutiplyWithOverflow(-1, -3);
1101 try (captureMultiply(i32){ .opA = 3 }).testMutiplyWithOverflow(-1, -3);
1102 try (captureMultiply(i64){ .opA = 3 }).testMutiplyWithOverflow(-1, -3);
1103}
1104
10761105test "@mulWithOverflow bitsize 128 bits" {
10771106 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
10781107 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;