From 55359e7d06465b2de047216e96885539ac89c644 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Wed, 1 Nov 2023 16:26:45 +0800 Subject: [PATCH] more fixes --- tests/ast/test_folding.py | 4 ++-- vyper/builtins/functions.py | 12 ++++++------ vyper/semantics/analysis/pre_typecheck.py | 10 +++------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/tests/ast/test_folding.py b/tests/ast/test_folding.py index 4b2f32e112..eed00215a8 100644 --- a/tests/ast/test_folding.py +++ b/tests/ast/test_folding.py @@ -200,7 +200,7 @@ def test_replace_constant(source): unmodified_ast = vy_ast.parse_to_ast(source) folded_ast = vy_ast.parse_to_ast(source) - folding.replace_constant(folded_ast, "FOO", vy_ast.Int(value=31337), UINT256_T, 31337, True) + folding.replace_constant(folded_ast, "FOO", vy_ast.Int(value=31337), UINT256_T, True) assert not vy_ast.compare_nodes(unmodified_ast, folded_ast) @@ -223,7 +223,7 @@ def test_replace_constant_no(source): unmodified_ast = vy_ast.parse_to_ast(source) folded_ast = vy_ast.parse_to_ast(source) - folding.replace_constant(folded_ast, "FOO", vy_ast.Int(value=31337), UINT256_T, 31337, True) + folding.replace_constant(folded_ast, "FOO", vy_ast.Int(value=31337), UINT256_T, True) assert vy_ast.compare_nodes(unmodified_ast, folded_ast) diff --git a/vyper/builtins/functions.py b/vyper/builtins/functions.py index 306129d1a0..8047374cea 100644 --- a/vyper/builtins/functions.py +++ b/vyper/builtins/functions.py @@ -141,11 +141,11 @@ class Floor(BuiltinFunction): def evaluate(self, node, skip_typecheck=False): validate_call_args(node, 1) - input_val = node.args[0]._metadata.get("folded_value") - if not isinstance(input_val, vy_ast.Decimal): + arg = node.args[0]._metadata.get("folded_value") + if not isinstance(arg, vy_ast.Decimal): raise UnfoldableNode - value = math.floor(input_val) + value = math.floor(arg.value) return vy_ast.Int.from_node(node, value=value) @process_inputs @@ -172,11 +172,11 @@ class Ceil(BuiltinFunction): def evaluate(self, node, skip_typecheck=False): validate_call_args(node, 1) - input_val = node.args[0]._metadata.get("folded_value") - if not isinstance(input_val, vy_ast.Decimal): + arg = node.args[0]._metadata.get("folded_value") + if not isinstance(arg, vy_ast.Decimal): raise UnfoldableNode - value = math.ceil(input_val) + value = math.ceil(arg.value) return vy_ast.Int.from_node(node, value=value) @process_inputs diff --git a/vyper/semantics/analysis/pre_typecheck.py b/vyper/semantics/analysis/pre_typecheck.py index e2747d3920..e828d1e527 100644 --- a/vyper/semantics/analysis/pre_typecheck.py +++ b/vyper/semantics/analysis/pre_typecheck.py @@ -256,7 +256,7 @@ def _subscriptable_helper(self, node): values = [get_folded_value(e) for e in node.elements] if None not in values: - node._metadata["folded_value"] = values + node._metadata["folded_value"] = type(node).from_node(node, elts=values) def visit_List(self, node): self._subscriptable_helper(node) @@ -269,8 +269,8 @@ def visit_Subscript(self, node): self.visit(node.slice) self.visit(node.value) - sliced = get_folded_value(node.slice) - index = get_folded_value(node.value) + index = get_folded_value(node.slice) + sliced = get_folded_value(node.value) if None not in (sliced, index): node._metadata["folded_value"] = sliced.elements[index.value] @@ -293,9 +293,5 @@ def visit_IfExp(self, node): def get_folded_value(node: vy_ast.VyperNode) -> Optional[vy_ast.VyperNode]: if isinstance(node, vy_ast.Constant): return node - elif isinstance(node, (vy_ast.List, vy_ast.Tuple)): - values = [get_folded_value(i) for i in node.elements] - if None not in values: - return values return node._metadata.get("folded_value")