Skip to content

Commit ae85fd0

Browse files
committed
[mypyc] feat: support constant folding in translate_index_expr
1 parent 053c054 commit ae85fd0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

mypyc/irbuild/expression.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,8 @@ def transform_index_expr(builder: IRBuilder, expr: IndexExpr) -> Value:
590590

591591
base = builder.accept(expr.base, can_borrow=can_borrow_base)
592592

593-
if isinstance(base.type, RTuple) and isinstance(index, IntExpr):
594-
return builder.add(TupleGet(base, index.value, expr.line))
593+
if isinstance(base.type, RTuple) and isinstance(folded_index := constant_fold_expr(builder, index), int):
594+
return builder.add(TupleGet(base, folded_index, expr.line))
595595

596596
if isinstance(index, SliceExpr):
597597
value = try_gen_slice_op(builder, base, index)

0 commit comments

Comments
 (0)