From c92d2e7c7f567e8bd40c631df4e00a4f466e5f70 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Thu, 26 Jan 2023 19:08:47 +0800 Subject: [PATCH 1/3] allow enum as mapping key --- vyper/semantics/types/user.py | 1 + 1 file changed, 1 insertion(+) diff --git a/vyper/semantics/types/user.py b/vyper/semantics/types/user.py index 926ac09245..ab5e5ce0aa 100644 --- a/vyper/semantics/types/user.py +++ b/vyper/semantics/types/user.py @@ -41,6 +41,7 @@ class EnumT(_UserType): # enums, but not static arrays of enums _as_darray = True _is_prim_word = True + _as_hashmap_key = True def __init__(self, name: str, members: dict) -> None: if len(members.keys()) > 256: From def23f6a83d2022a6175d72962823cac78cc4419 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Thu, 26 Jan 2023 19:08:52 +0800 Subject: [PATCH 2/3] add test --- tests/parser/types/test_enum.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/parser/types/test_enum.py b/tests/parser/types/test_enum.py index 3884e9a5a1..270484d94e 100644 --- a/tests/parser/types/test_enum.py +++ b/tests/parser/types/test_enum.py @@ -276,3 +276,20 @@ def get_enum_from_struct() -> Foobar: """ c = get_contract_with_gas_estimation(code) assert c.get_enum_from_struct() == 2 + + +def test_mapping_with_enum(get_contract_with_gas_estimation): + code = """ +enum Foobar: + FOO + BAR + +fb: HashMap[Foobar, uint256] + +@external +def get_key(f: Foobar, i: uint256) -> uint256: + self.fb[f] = i + return self.fb[f] + """ + c = get_contract_with_gas_estimation(code) + assert c.get_key(1, 777) == 777 \ No newline at end of file From 931354928b844d83aaec199ab884f2917f8d3865 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Thu, 26 Jan 2023 19:13:49 +0800 Subject: [PATCH 3/3] fix lint --- tests/parser/types/test_enum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/parser/types/test_enum.py b/tests/parser/types/test_enum.py index 270484d94e..201d1ba9d0 100644 --- a/tests/parser/types/test_enum.py +++ b/tests/parser/types/test_enum.py @@ -292,4 +292,4 @@ def get_key(f: Foobar, i: uint256) -> uint256: return self.fb[f] """ c = get_contract_with_gas_estimation(code) - assert c.get_key(1, 777) == 777 \ No newline at end of file + assert c.get_key(1, 777) == 777