Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow enum as mapping key #3256

Merged
merged 3 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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