Skip to content

Commit

Permalink
fix: bitwise not constant folding (#3222)
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg authored Jan 20, 2023
1 parent d59ffaa commit deb3378
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tests/builtins/folding/test_bitwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def foo(a: uint256) -> uint256:
"""
contract = get_contract(source)

vyper_ast = vy_ast.parse_to_ast(f"bitwise_not({value})")
vyper_ast = vy_ast.parse_to_ast(f"~{value}")
old_node = vyper_ast.body[0].value
new_node = vy_fn.BitwiseNot().evaluate(old_node)
new_node = old_node.evaluate()

assert contract.foo(value) == new_node.value

Expand Down
4 changes: 3 additions & 1 deletion vyper/ast/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,9 @@ class Invert(Operator):
__slots__ = ()
_description = "bitwise not"
_pretty = "~"
_op = operator.inv

def _op(self, value):
return (2 ** 256 - 1) ^ value


class BinOp(ExprNode):
Expand Down

0 comments on commit deb3378

Please # to comment.