From 389842fc633c21b387da0d4ecfa2bf613e74f169 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:41:57 +0800 Subject: [PATCH] fix constant folding --- vyper/semantics/analysis/constant_folding.py | 7 ++++--- vyper/semantics/analysis/utils.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/vyper/semantics/analysis/constant_folding.py b/vyper/semantics/analysis/constant_folding.py index 98cab0f8cb..6f885f025d 100644 --- a/vyper/semantics/analysis/constant_folding.py +++ b/vyper/semantics/analysis/constant_folding.py @@ -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 diff --git a/vyper/semantics/analysis/utils.py b/vyper/semantics/analysis/utils.py index a31ce7acc1..a8e13a06a4 100644 --- a/vyper/semantics/analysis/utils.py +++ b/vyper/semantics/analysis/utils.py @@ -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.) @@ -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: