Skip to content

Commit

Permalink
Add UInt debug_assert(value >= 0) for Int implicit conversion
Browse files Browse the repository at this point in the history
Signed-off-by: martinvuyk <[email protected]>
  • Loading branch information
martinvuyk committed Nov 6, 2024
1 parent cf570c3 commit 47002e3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions stdlib/src/builtin/uint.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 47002e3

Please sign in to comment.