Skip to content

Commit 2dca054

Browse files
committed
fix
1 parent c9709b9 commit 2dca054

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

helion/_compiler/device_ir.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,8 +1166,9 @@ def visit_Subscript(self, node: ast.Subscript) -> object:
11661166
assert isinstance(value, ExtendedAST)
11671167
type_info = value._type_info
11681168
if isinstance(type_info, SequenceType):
1169-
if isinstance(node.slice, ast.Constant):
1170-
return self.visit(value)[self.visit(node.slice)] # pyright: ignore[reportIndexIssue]
1169+
index_value = self.visit(node.slice)
1170+
if isinstance(index_value, int):
1171+
return self.visit(value)[index_value] # pyright: ignore[reportIndexIssue]
11711172
raise exc.InvalidSequenceSubscription(node.slice)
11721173
if isinstance(type_info, StackTensorType):
11731174
return hl.load(self.visit(value), self._subscript_slice_proxy(node.slice)) # pyright: ignore[reportArgumentType]

helion/_compiler/type_propagation.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,17 @@ def populate_symbol_origins(self, origin: Origin) -> None:
12731273
subtype.populate_symbol_origins(GetItemOrigin(origin, i))
12741274

12751275
def propagate_getitem(self, key: TypeInfo, origin: Origin) -> TypeInfo:
1276+
# Tuple indexing with non-literal indices (e.g., from hl.static_range)
1277+
if self.python_type is tuple and isinstance(key, SymIntType):
1278+
if not self.element_types:
1279+
raise exc.TypeInferenceError("Cannot index empty tuple")
1280+
first_type = self.element_types[0]
1281+
if not all(type(e) is type(first_type) for e in self.element_types[1:]):
1282+
raise exc.TypeInferenceError(
1283+
"Tuple indexing with non-literal index requires all elements to have the same type"
1284+
)
1285+
return first_type
1286+
12761287
return super().propagate_getitem(key, origin)
12771288

12781289
def merge(self, other: TypeInfo, var_name: str | None = None) -> TypeInfo:

0 commit comments

Comments
 (0)