KT-16437 Incorrect type inference for some when coerced to Unit
If the result of 'when' is not used in an expression, this 'when' expression has type 'Unit' despite of whatever FE has inferred.
This commit is contained in:
+6
-1
@@ -85,7 +85,12 @@ class BranchingExpressionGenerator(statementGenerator: StatementGenerator) : Sta
|
||||
scope.createTemporaryVariable(statementGenerator.generateExpression(it), "subject")
|
||||
}
|
||||
|
||||
val resultType = 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 irWhen = IrWhenImpl(expression.startOffset, expression.endOffset, resultType, IrStatementOrigin.WHEN)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user