authorgravatar for mathieusuen@yahoo.frMathieu Suen <mathieusuen@yahoo.fr> 2026-02-18 19:20:44+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-04-10 23:23:33+02:00
log244f5aafca25c2151fbdf80e54c1e8e08153a877
treedd70bd166ad8a86e561751038e517c843705ea6e
parent7addae8f7df4305d588c1583036d69a1ae08030c

fixup! Adding unwrapped error multiply regression test


1 files changed, 8 insertions(+), 18 deletions(-)

test/behavior/math.zig+8-18
...@@ -1073,21 +1073,11 @@ test "@mulWithOverflow bitsize > 32" {...@@ -1073,21 +1073,11 @@ test "@mulWithOverflow bitsize > 32" {
1073 try testMulWithOverflow(i63, minInt(i63), minInt(i63), 0, 1);1073 try testMulWithOverflow(i63, minInt(i63), minInt(i63), 0, 1);
1074}1074}
10751075
1076fn captureMultiply(comptime T: type) type {1076fn testMutiplyUnwrap(comptime T: type, wrapped_a: anyerror!T, comptime b: T, expected: T) !void {
1077 return struct {1077 const a = try wrapped_a;
1078 opA: T,
10791078
1080 fn returnA(self: @This()) anyerror!T {1079 const c = a * b;
1081 return self.opA;1080 try expect(expected == c);
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}1081}
10921082
1093test "Multiply unwrap error * immediate" {1083test "Multiply unwrap error * immediate" {
...@@ -1096,10 +1086,10 @@ test "Multiply unwrap error * immediate" {...@@ -1096,10 +1086,10 @@ test "Multiply unwrap error * immediate" {
1096 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;1086 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1097 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;1087 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
10981088
1099 try (captureMultiply(i8){ .opA = 3 }).testMutiplyWithOverflow(-1, -3);1089 try testMutiplyUnwrap(i8, 3, -1, -3);
1100 try (captureMultiply(i16){ .opA = 3 }).testMutiplyWithOverflow(-1, -3);1090 try testMutiplyUnwrap(i16, 3, -1, -3);
1101 try (captureMultiply(i32){ .opA = 3 }).testMutiplyWithOverflow(-1, -3);1091 try testMutiplyUnwrap(i32, 3, -1, -3);
1102 try (captureMultiply(i64){ .opA = 3 }).testMutiplyWithOverflow(-1, -3);1092 try testMutiplyUnwrap(i64, 3, -1, -3);
1103}1093}
11041094
1105test "@mulWithOverflow bitsize 128 bits" {1095test "@mulWithOverflow bitsize 128 bits" {