Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix[ux]: fix false positive for overflow in type checker #4385

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/functional/codegen/types/numbers/test_exponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,17 @@ def foo(b: int128) -> int128:
c.foo(max_power)
with tx_failed():
c.foo(max_power + 1)


valid_list = [
"""
@external
def foo() -> uint256:
return (10**18)**2
"""
]


@pytest.mark.parametrize("good_code", valid_list)
def test_exponent_success(good_code):
assert compile_code(good_code) is not None
2 changes: 1 addition & 1 deletion vyper/semantics/analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _validate_op(node, types_list, validation_fn_name):
try:
_validate_fn(node)
ret.append(type_)
except InvalidOperation as e:
except (InvalidOperation, OverflowException) as e:
err_list.append(e)

if ret:
Expand Down
4 changes: 2 additions & 2 deletions vyper/semantics/types/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ def _get_lr():
if isinstance(left, vy_ast.Int):
if left.value >= 2**value_bits:
raise OverflowException(
"Base is too large, calculation will always overflow", left
f"Base is too large for {self}, calculation will always overflow", left
)
elif left.value < -(2**value_bits):
raise OverflowException(
"Base is too small, calculation will always underflow", left
f"Base is too small for {self}, calculation will always underflow", left
)
elif isinstance(right, vy_ast.Int):
if right.value < 0:
Expand Down
Loading