Skip to content

Commit 0544fb1

Browse files
Update constant_fold.py
1 parent 8d44ae0 commit 0544fb1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

mypyc/irbuild/constant_fold.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from mypy.nodes import (
1717
BytesExpr,
1818
ComplexExpr,
19+
ConditionalExpr,
1920
Expression,
2021
FloatExpr,
2122
IntExpr,
@@ -72,6 +73,11 @@ def constant_fold_expr(builder: IRBuilder, expr: Expression) -> ConstantValue |
7273
value = constant_fold_expr(builder, expr.expr)
7374
if value is not None and not isinstance(value, bytes):
7475
return constant_fold_unary_op(expr.op, value)
76+
elif isinstance(expr, ConditionalExpr):
77+
cond = constant_fold_expr(builder, expr.cond)
78+
if cond is not None:
79+
value_expr = expr.if_expr if cond else expr.else_expr
80+
return constant_fold_expr(builder, expr.cond)
7581
return None
7682

7783

0 commit comments

Comments
 (0)