Skip to content
Open
Changes from 3 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
11 changes: 9 additions & 2 deletions mypyc/ir/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,10 +1045,17 @@ class TupleGet(RegisterOp):

def __init__(self, src: Value, index: int, line: int = -1, *, borrow: bool = False) -> None:
super().__init__(line)
assert isinstance(
src.type, RTuple
), "TupleGet only operates on tuples, not {type(src.type).__name__}"
src_len = len(src.type.types)
self.src = src
self.index = index
assert isinstance(src.type, RTuple), "TupleGet only operates on tuples"
assert index >= 0
if index < 0:
self.index += src_len
assert (
self.index <= src_len - 1
), f"Index out of range.\nsource type: {src.type}\nindex: {index}"
self.type = src.type.types[index]
self.is_borrowed = borrow

Expand Down