[NI] Fix coercion to Unit for lambdas with empty labeled return

This commit is contained in:
Mikhail Zarechenskiy
2019-01-29 15:37:27 +03:00
parent 147d7844bc
commit 6705803d83
7 changed files with 136 additions and 2 deletions
@@ -178,10 +178,10 @@ class KotlinResolutionCallbacksImpl(
}
val lastExpressionArgument = getLastDeparentesizedExpression(psiCallArgument)?.let { lastExpression ->
if (expectedReturnType?.isUnit() == true) return@let null // coercion to Unit
if (expectedReturnType?.isUnit() == true || hasReturnWithoutExpression) return@let null // coercion to Unit
// todo lastExpression can be if without else
val lastExpressionType = if (hasReturnWithoutExpression) null else trace.getType(lastExpression)
val lastExpressionType = trace.getType(lastExpression)
val contextInfo = lambdaInfo.lastExpressionInfo
val lastExpressionTypeInfo = KotlinTypeInfo(lastExpressionType, contextInfo.dataFlowInfoAfter ?: functionTypeInfo.dataFlowInfo)
createCallArgument(lastExpression, lastExpressionTypeInfo, contextInfo.lexicalScope, contextInfo.trace)