From 7d0b2b433fcd29f9311035eba2449d8b2f312d09 Mon Sep 17 00:00:00 2001 From: Hila Friedman Date: Fri, 20 Sep 2024 10:02:23 +0300 Subject: [PATCH] Add compile error for bad types --- lib/std/math/gcd.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/std/math/gcd.zig b/lib/std/math/gcd.zig index f35d81125f75..16ca7846f19a 100644 --- a/lib/std/math/gcd.zig +++ b/lib/std/math/gcd.zig @@ -9,7 +9,9 @@ pub fn gcd(a: anytype, b: anytype) @TypeOf(a, b) { comptime_int => std.math.IntFittingRange(@min(a, b), @max(a, b)), else => |T| T, }; - comptime std.debug.assert(@typeInfo(N).Int.signedness == .unsigned); + if (@typeInfo(N) != .int or @typeInfo(N).int.signedness != .unsigned) { + @compileError("`a` and `b` must be usigned integers"); + } // using an optimised form of Stein's algorithm: // https://en.wikipedia.org/wiki/Binary_GCD_algorithm