Fix CFG problem for 'when' in Konan
If type of 'when' expression is 'Nothing', it should be kept that way even if the expression itself is implicitly coerced to Unit.
This commit is contained in:
+11
-5
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.psi2ir.generators
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.whenComma
|
||||
import org.jetbrains.kotlin.ir.declarations.IrVariable
|
||||
@@ -85,12 +86,17 @@ class BranchingExpressionGenerator(statementGenerator: StatementGenerator) : Sta
|
||||
scope.createTemporaryVariable(statementGenerator.generateExpression(it), "subject")
|
||||
}
|
||||
|
||||
|
||||
val inferredType = getInferredTypeWithImplicitCastsOrFail(expression)
|
||||
|
||||
// TODO relies on ControlFlowInformationProvider, get rid of it
|
||||
val resultType =
|
||||
if (context.bindingContext[BindingContext.USED_AS_EXPRESSION, expression] ?: false)
|
||||
getInferredTypeWithImplicitCastsOrFail(expression)
|
||||
else
|
||||
context.builtIns.unitType
|
||||
val isUsedAsExpression = context.bindingContext[BindingContext.USED_AS_EXPRESSION, expression] ?: false
|
||||
|
||||
val resultType = when {
|
||||
isUsedAsExpression -> inferredType
|
||||
KotlinBuiltIns.isNothing(inferredType) -> inferredType
|
||||
else -> context.builtIns.unitType
|
||||
}
|
||||
|
||||
val irWhen = IrWhenImpl(expression.startOffset, expression.endOffset, resultType, IrStatementOrigin.WHEN)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user