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[lang]: fix pow folding when args are not literals #3949

Merged
merged 2 commits into from
Apr 15, 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
10 changes: 10 additions & 0 deletions tests/functional/codegen/types/numbers/test_exponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ def f0():
compile_code(code)


def test_fold_nonliteral(get_contract):
# test we can fold non-literal constants
code = """
N: constant(uint256) = 3
N2: public(constant(uint256)) = N**N
"""
c = get_contract(code)
assert c.N2() == 3**3


@pytest.mark.fuzzing
@pytest.mark.parametrize("power", range(2, 255))
def test_exp_uint256(get_contract, tx_failed, power):
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 @@ -151,9 +151,9 @@ def validate_numeric_op(

def _get_lr():
if isinstance(node, vy_ast.BinOp):
return node.left, node.right
return node.left.reduced(), node.right.reduced()
elif isinstance(node, vy_ast.AugAssign):
return node.target, node.value
return node.target.reduced(), node.value.reduced()
else:
raise CompilerPanic(f"Unexpected node type for numeric op: {type(node).__name__}")

Expand Down
Loading