diff --git a/vyper/codegen/expr.py b/vyper/codegen/expr.py index be7a69de77..2dd254eb68 100644 --- a/vyper/codegen/expr.py +++ b/vyper/codegen/expr.py @@ -70,8 +70,8 @@ class Expr: # TODO: Once other refactors are made reevaluate all inline imports def __init__(self, node, context): - if isinstance(node, vy_ast.VyperNode): - node = node.get_folded_value() if node.has_folded_value else node + if isinstance(node, vy_ast.VyperNode) and node.has_folded_value: + node = node.get_folded_value() self.expr = node self.context = context @@ -193,9 +193,8 @@ def parse_Name(self): # using the folded value metadata assert isinstance(varinfo.typ, StructT) value_node = varinfo.decl_node.value - value_node = ( - value_node.get_folded_value() if value_node.has_folded_value else value_node - ) + if value_node.has_folded_value: + value_node = value_node.get_folded_value() return Expr.parse_value_expr(value_node, self.context) assert varinfo.modifiability == Modifiability.IMMUTABLE, "not an immutable!" diff --git a/vyper/semantics/analysis/local.py b/vyper/semantics/analysis/local.py index 5683883da6..f701e5f4a7 100644 --- a/vyper/semantics/analysis/local.py +++ b/vyper/semantics/analysis/local.py @@ -758,15 +758,8 @@ def _analyse_range_call(node: vy_ast.Call) -> list[VyperType]: """ validate_call_args(node, (1, 2), kwargs=["bound"]) kwargs = {s.arg: s.value for s in node.keywords or []} - arg0 = node.args[0].get_folded_value if node.args[0].has_folded_value else node.args[0] - start, end = ( - (vy_ast.Int(value=0), arg0) - if len(node.args) == 1 - else ( - arg0, - node.args[1].get_folded_value() if node.args[1].has_folded_value else node.args[1], - ) - ) + start, end = (vy_ast.Int(value=0), node.args[0]) if len(node.args) == 1 else node.args + start, end = [i.get_folded_value() if i.has_folded_value else i for i in (start, end)] all_args = (start, end, *kwargs.values()) for arg1 in all_args: @@ -778,10 +771,11 @@ def _analyse_range_call(node: vy_ast.Call) -> list[VyperType]: if "bound" in kwargs: bound = kwargs["bound"] - folded_bound = bound.get_folded_value() if bound.has_folded_value else bound - if not isinstance(folded_bound, vy_ast.Num): + if bound.has_folded_value: + bound = bound.get_folded_value() + if not isinstance(bound, vy_ast.Num): raise StateAccessViolation("Bound must be a literal", bound) - if folded_bound.value <= 0: + if bound.value <= 0: raise StructureException("Bound must be at least 1", bound) if isinstance(start, vy_ast.Num) and isinstance(end, vy_ast.Num): error = "Please remove the `bound=` kwarg when using range with constants" diff --git a/vyper/semantics/types/subscriptable.py b/vyper/semantics/types/subscriptable.py index c3c86e12ad..55ffc23b2f 100644 --- a/vyper/semantics/types/subscriptable.py +++ b/vyper/semantics/types/subscriptable.py @@ -288,9 +288,8 @@ def from_annotation(cls, node: vy_ast.Subscript) -> "DArrayT": raise StructureException(err_msg, node.slice) length_node = node.slice.value.elements[1] - length_node = ( - length_node.get_folded_value() if length_node.has_folded_value else length_node - ) + if length_node.has_folded_value: + length_node = length_node.get_folded_value() if not isinstance(length_node, vy_ast.Int): raise StructureException(err_msg, length_node) diff --git a/vyper/semantics/types/utils.py b/vyper/semantics/types/utils.py index a696682e0e..bcd01bbdbb 100644 --- a/vyper/semantics/types/utils.py +++ b/vyper/semantics/types/utils.py @@ -179,7 +179,10 @@ def get_index_value(node: vy_ast.Index) -> int: # TODO: revisit this! from vyper.semantics.analysis.utils import get_possible_types_from_node - value = node.value.get_folded_value() if node.value.has_folded_value else node.value + value = node.value + if value.has_folded_value: + value = value.get_folded_value() + if not isinstance(value, vy_ast.Int): if hasattr(node, "value"): # even though the subscript is an invalid type, first check if it's a valid _something_