Skip to content

Commit

Permalink
fix constant folding
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Dec 6, 2024
1 parent 05f6757 commit 389842f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions vyper/semantics/analysis/constant_folding.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ def visit_UnaryOp(self, node):

def visit_BinOp(self, node):
left, right = [i.get_folded_value() for i in (node.left, node.right)]
if type(left) is not type(right):
raise UnfoldableNode("invalid operation", node)
if not isinstance(left, vy_ast.Num):
valid_integer_nodes = (vy_ast.Hex, vy_ast.Int)
if not type(left) not in valid_integer_nodes:
raise UnfoldableNode("not a number!", node.left)
if not type(right) not in valid_integer_nodes:
raise UnfoldableNode("invalid operation", node)

# this validation is performed to prevent the compiler from hanging
# on very large shifts and improve the error message for negative
Expand Down
3 changes: 2 additions & 1 deletion vyper/semantics/analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def types_from_Constant(self, node):
if not isinstance(node, t._valid_literal):
continue

print("type: ", t)
# special handling for bytestrings since their
# class objects are in the type map, not the type itself
# (worth rethinking this design at some point.)
Expand All @@ -315,7 +316,7 @@ def types_from_Constant(self, node):
# any more validation which needs to occur
t.validate_literal(node)
types_list.append(t)
except VyperException:
except VyperException as e:
continue

if types_list:
Expand Down

0 comments on commit 389842f

Please sign in to comment.