From d59ffaa13ce6cfae6912e0250469992993ec4d72 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Fri, 20 Jan 2023 09:53:08 +0800 Subject: [PATCH] fix: skip enum members during constant folding (#3235) --- tests/parser/syntax/test_enum.py | 6 ++++++ vyper/ast/folding.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/tests/parser/syntax/test_enum.py b/tests/parser/syntax/test_enum.py index 267de2180f..fe7b9fc83d 100644 --- a/tests/parser/syntax/test_enum.py +++ b/tests/parser/syntax/test_enum.py @@ -137,6 +137,12 @@ def run() -> Order: }) """, "enum Foo:\n" + "\n".join([f" member{i}" for i in range(256)]), + """ +a: constant(uint256) = 1 + +enum A: + a + """, ] diff --git a/vyper/ast/folding.py b/vyper/ast/folding.py index baf3f48336..8d89d85b41 100644 --- a/vyper/ast/folding.py +++ b/vyper/ast/folding.py @@ -284,6 +284,10 @@ def replace_constant( if assign and node in assign.target.get_descendants(include_self=True): continue + # do not replace enum members + if node.get_ancestor(vy_ast.EnumDef): + continue + try: # note: _replace creates a copy of the replacement_node new_node = _replace(node, replacement_node, type_=type_)