Skip to content
Open
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
32 changes: 32 additions & 0 deletions tests/functional/syntax/test_hashmap_container_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest

from vyper.compiler import compile_code

valid_list = [
"""
d: HashMap[uint256, HashMap[uint256, uint256]]

@external
def foo() -> uint256:
return self.d[0][0]
""",
"""
d: HashMap[uint256, uint256[10]]

@external
def foo() -> uint256:
return self.d[0][0]
""",
"""
d: HashMap[uint256, (uint256, uint256)]

@external
def foo() -> uint256:
return self.d[0][0]
""",
]


@pytest.mark.parametrize("good_code", valid_list)
def test_list_success(good_code):
assert compile_code(good_code) is not None
8 changes: 7 additions & 1 deletion vyper/semantics/analysis/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,13 @@ def visit_Subscript(self, node: vy_ast.Subscript, typ: VyperType) -> None:
possible_base_types = get_possible_types_from_node(node.value)

for possible_type in possible_base_types:
if typ.compare_type(possible_type.value_type):
if isinstance(possible_type, TupleT):
assert isinstance(node.slice, vy_ast.Int) # help mypy
value_type = possible_type.member_types[node.slice.value]
else:
value_type = possible_type.value_type

if typ.compare_type(value_type):
base_type = possible_type
break
else:
Expand Down
Loading