Skip to content

Commit

Permalink
fix: allow enum as mapping key (#3256)
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg authored Feb 1, 2023
1 parent f3c8cb9 commit ddb402b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/parser/types/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions vyper/semantics/types/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ddb402b

Please sign in to comment.