[FIR] Don't constraints for return expressions of lambda if it has Unit return type

This commit is contained in:
Dmitriy Novozhilov
2020-09-11 15:38:04 +03:00
parent 8e0d0d2fd8
commit def647c094
5 changed files with 34 additions and 4 deletions
@@ -0,0 +1,9 @@
class DropDownComponent<T : Any>(val initialValues: List<T>)
fun test(strings: List<String>) {
val dropDown = DropDownComponent(
initialValues = buildList {
addAll(strings)
}
)
}
@@ -0,0 +1,16 @@
FILE: builderInferenceAndCoercionToUnit.kt
public final class DropDownComponent<T : R|kotlin/Any|> : R|kotlin/Any| {
public constructor<T : R|kotlin/Any|>(initialValues: R|kotlin/collections/List<T>|): R|DropDownComponent<T>| {
super<R|kotlin/Any|>()
}
public final val initialValues: R|kotlin/collections/List<T>| = R|<local>/initialValues|
public get(): R|kotlin/collections/List<T>|
}
public final fun test(strings: R|kotlin/collections/List<kotlin/String>|): R|kotlin/Unit| {
lval dropDown: R|DropDownComponent<kotlin/String>| = R|/DropDownComponent.DropDownComponent|<R|kotlin/String|>(initialValues = R|kotlin/collections/buildList|<R|kotlin/String|>(<L> = buildList@fun R|kotlin/collections/MutableList<kotlin/String>|.<anonymous>(): R|kotlin/Unit| <kind=EXACTLY_ONCE> {
this@R|special/anonymous|.R|FakeOverride<kotlin/collections/MutableList.addAll: R|kotlin/Boolean|>|(R|<local>/strings|)
}
))
}
@@ -847,6 +847,11 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/builderInference.kt");
}
@TestMetadata("builderInferenceAndCoercionToUnit.kt")
public void testBuilderInferenceAndCoercionToUnit() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/builderInferenceAndCoercionToUnit.kt");
}
@TestMetadata("builderInferenceFromStdlib.kt")
public void testBuilderInferenceFromStdlib() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/builderInferenceFromStdlib.kt");
@@ -294,7 +294,7 @@ private enum class VarargMappingState {
private fun FirFunction<*>.indexOf(valueParameter: FirValueParameter): Int = valueParameters.indexOf(valueParameter)
private val ConeKotlinType.isUnit: Boolean
val ConeKotlinType.isUnit: Boolean
get() {
val type = this.lowerBoundIfFlexible()
if (type.isNullable) return false
@@ -154,13 +154,14 @@ class PostponedArgumentsAnalyzer(
val checkerSink: CheckerSink = CheckerSinkImpl()
var hasExpressionInReturnArguments = false
val lambdaReturnType = lambda.returnType.let(::substitute).takeUnless { it.isUnit }
returnArguments.forEach {
if (it !is FirExpression) return@forEach
hasExpressionInReturnArguments = true
candidate.resolveArgumentExpression(
c.getBuilder(),
it,
lambda.returnType.let(::substitute),
lambdaReturnType,
lambda.atom.returnTypeRef, // TODO: proper ref
checkerSink,
context = resolutionContext,
@@ -169,8 +170,7 @@ class PostponedArgumentsAnalyzer(
)
}
if (!hasExpressionInReturnArguments) {
val lambdaReturnType = lambda.returnType.let(::substitute)
if (!hasExpressionInReturnArguments && lambdaReturnType != null) {
/*LambdaArgumentConstraintPosition(lambda)*/
c.getBuilder().addEqualityConstraint(lambdaReturnType, unitType, SimpleConstraintSystemConstraintPosition)
}