@@ -2635,8 +2635,15 @@ open class KotlinFileExtractor(
26352635 }
26362636 }
26372637 is IrWhen -> {
2638- if (e.origin == IrStatementOrigin .ANDAND ||
2639- e.origin == IrStatementOrigin .OROR ) {
2638+ val isAndAnd = e.origin == IrStatementOrigin .ANDAND
2639+ val isOrOr = e.origin == IrStatementOrigin .OROR
2640+
2641+ if ((isAndAnd || isOrOr) &&
2642+ e.branches.size == 2 &&
2643+ e.branches[1 ].condition is IrConst <* > &&
2644+ (e.branches[1 ].condition as IrConst <* >).value == true &&
2645+ e.branches[if (e.origin == IrStatementOrigin .ANDAND ) 1 else 0 ].result is IrConst <* > &&
2646+ (e.branches[if (e.origin == IrStatementOrigin .ANDAND ) 1 else 0 ].result as IrConst <* >).value == isOrOr) {
26402647
26412648 // resugar binary logical operators:
26422649
@@ -2660,14 +2667,9 @@ open class KotlinFileExtractor(
26602667 tw.writeCallableEnclosingExpr(id, callable)
26612668 tw.writeStatementEnclosingExpr(id, exprParent.enclosingStmt)
26622669
2663- if (e.branches.size != 2 ) {
2664- logger.errorElement(" Expected to find 2 when branches for ${e.origin} , found ${e.branches.size} " , e)
2665- return
2666- }
2667-
26682670 extractExpressionExpr(e.branches[0 ].condition, callable, id, 0 , exprParent.enclosingStmt)
26692671
2670- var rhsIdx = if (e.origin == IrStatementOrigin .ANDAND ) 0 else 1
2672+ var rhsIdx = if (e.origin == IrStatementOrigin .ANDAND ) 0 else 1
26712673 extractExpressionExpr(e.branches[rhsIdx].result, callable, id, 1 , exprParent.enclosingStmt)
26722674
26732675 return
0 commit comments