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: typechecking of folded builtins #3490

Merged
merged 2 commits into from
Jul 1, 2023
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
27 changes: 27 additions & 0 deletions tests/parser/syntax/test_addmulmod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest

from vyper.exceptions import InvalidType

fail_list = [
( # bad AST nodes given as arguments
"""
@external
def foo() -> uint256:
return uint256_addmod(1.1, 1.2, 3.0)
""",
InvalidType,
),
( # bad AST nodes given as arguments
"""
@external
def foo() -> uint256:
return uint256_mulmod(1.1, 1.2, 3.0)
""",
InvalidType,
),
]


@pytest.mark.parametrize("code,exc", fail_list)
def test_add_mod_fail(assert_compile_failed, get_contract, code, exc):
assert_compile_failed(lambda: get_contract(code), exc)
14 changes: 7 additions & 7 deletions vyper/builtins/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ def evaluate(self, node):

validate_call_args(node, 2)
for arg in node.args:
if not isinstance(arg, vy_ast.Num):
if not isinstance(arg, vy_ast.Int):
raise UnfoldableNode
if arg.value < 0 or arg.value >= 2**256:
raise InvalidLiteral("Value out of range for uint256", arg)
Expand All @@ -1396,7 +1396,7 @@ def evaluate(self, node):

validate_call_args(node, 2)
for arg in node.args:
if not isinstance(arg, vy_ast.Num):
if not isinstance(arg, vy_ast.Int):
raise UnfoldableNode
if arg.value < 0 or arg.value >= 2**256:
raise InvalidLiteral("Value out of range for uint256", arg)
Expand All @@ -1422,7 +1422,7 @@ def evaluate(self, node):

validate_call_args(node, 2)
for arg in node.args:
if not isinstance(arg, vy_ast.Num):
if not isinstance(arg, vy_ast.Int):
raise UnfoldableNode
if arg.value < 0 or arg.value >= 2**256:
raise InvalidLiteral("Value out of range for uint256", arg)
Expand All @@ -1447,7 +1447,7 @@ def evaluate(self, node):
self.__class__._warned = True

validate_call_args(node, 1)
if not isinstance(node.args[0], vy_ast.Num):
if not isinstance(node.args[0], vy_ast.Int):
raise UnfoldableNode

value = node.args[0].value
Expand All @@ -1474,7 +1474,7 @@ def evaluate(self, node):
self.__class__._warned = True

validate_call_args(node, 2)
if [i for i in node.args if not isinstance(i, vy_ast.Num)]:
if [i for i in node.args if not isinstance(i, vy_ast.Int)]:
raise UnfoldableNode
value, shift = [i.value for i in node.args]
if value < 0 or value >= 2**256:
Expand Down Expand Up @@ -1522,10 +1522,10 @@ class _AddMulMod(BuiltinFunction):

def evaluate(self, node):
validate_call_args(node, 3)
if isinstance(node.args[2], vy_ast.Num) and node.args[2].value == 0:
if isinstance(node.args[2], vy_ast.Int) and node.args[2].value == 0:
raise ZeroDivisionException("Modulo by 0", node.args[2])
for arg in node.args:
if not isinstance(arg, vy_ast.Num):
if not isinstance(arg, vy_ast.Int):
raise UnfoldableNode
if arg.value < 0 or arg.value >= 2**256:
raise InvalidLiteral("Value out of range for uint256", arg)
Expand Down