diff --git a/stdlib/src/builtin/uint.mojo b/stdlib/src/builtin/uint.mojo index 9c744052df..c6a3eee39c 100644 --- a/stdlib/src/builtin/uint.mojo +++ b/stdlib/src/builtin/uint.mojo @@ -87,6 +87,9 @@ struct UInt(IntLike, _HashableWithHasher): Args: value: The init value. """ + debug_assert( + value >= 0, "Constructing UInt from negative Int is discouraged." + ) self.value = value.value @always_inline("nodebug") @@ -96,6 +99,9 @@ struct UInt(IntLike, _HashableWithHasher): Args: value: The init value. """ + debug_assert( + value >= 0, "Constructing UInt from negative Int is discouraged." + ) self = value.__uint__() @always_inline("nodebug")