Add check already fixed variables in PostponedArgumentInputTypesResolver during adding constraints on them and using inside a functional type

^KT-42374 Fixed
This commit is contained in:
Victor Petukhov
2020-10-01 19:20:57 +03:00
parent 96ccf03794
commit 6c1dc43d25
8 changed files with 39 additions and 1 deletions
@@ -11085,6 +11085,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/callableReferences.kt");
}
@TestMetadata("fixingVariableDuringAddingConstraintForFirstPosponedArgument.kt")
public void testFixingVariableDuringAddingConstraintForFirstPosponedArgument() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/fixingVariableDuringAddingConstraintForFirstPosponedArgument.kt");
}
@TestMetadata("lackOfDeepIncorporation.kt")
public void testLackOfDeepIncorporation() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/lackOfDeepIncorporation.kt");
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.types.model.TypeVariableMarker
interface ConstraintSystemCompletionContext : VariableFixationFinder.Context, ResultTypeResolver.Context {
val allTypeVariables: Map<TypeConstructorMarker, TypeVariableMarker>
override val notFixedTypeVariables: Map<TypeConstructorMarker, VariableWithConstraints>
override val fixedTypeVariables: Map<TypeConstructorMarker, KotlinTypeMarker>
override val postponedTypeVariables: List<TypeVariableMarker>
fun getBuilder(): ConstraintSystemBuilder
@@ -20,6 +20,7 @@ class VariableFixationFinder(
) {
interface Context : TypeSystemInferenceExtensionContext {
val notFixedTypeVariables: Map<TypeConstructorMarker, VariableWithConstraints>
val fixedTypeVariables: Map<TypeConstructorMarker, KotlinTypeMarker>
val postponedTypeVariables: List<TypeVariableMarker>
fun isReified(variable: TypeVariableMarker): Boolean
}
@@ -220,9 +220,12 @@ class PostponedArgumentInputTypesResolver(
return allGroupedParameterTypes.mapIndexed { index, types ->
val parameterTypeVariable = createTypeVariableForParameterType(argument, index)
val typeVariableConstructor = parameterTypeVariable.freshTypeConstructor
for (typeWithKind in types) {
if (typeVariableConstructor in fixedTypeVariables) break
if (typeWithKind == null) continue
when (typeWithKind.direction) {
ConstraintKind.EQUALITY -> csBuilder.addEqualityConstraint(
parameterTypeVariable.defaultType, typeWithKind.type, ArgumentConstraintPositionImpl(atom)
@@ -236,7 +239,13 @@ class PostponedArgumentInputTypesResolver(
}
}
parameterTypeVariable.defaultType.asTypeProjection()
val resultType = if (typeVariableConstructor in fixedTypeVariables) {
fixedTypeVariables[typeVariableConstructor] as KotlinType
} else {
parameterTypeVariable.defaultType
}
resultType.asTypeProjection()
}
}
@@ -0,0 +1,8 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER
fun f(p: (Int) -> (String) -> Unit) {}
fun g(cond: Boolean) {
f(if (cond) { i -> { } } else { i -> { } })
}
@@ -0,0 +1,4 @@
package
public fun f(/*0*/ p: (kotlin.Int) -> (kotlin.String) -> kotlin.Unit): kotlin.Unit
public fun g(/*0*/ cond: kotlin.Boolean): kotlin.Unit
@@ -11092,6 +11092,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/callableReferences.kt");
}
@TestMetadata("fixingVariableDuringAddingConstraintForFirstPosponedArgument.kt")
public void testFixingVariableDuringAddingConstraintForFirstPosponedArgument() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/fixingVariableDuringAddingConstraintForFirstPosponedArgument.kt");
}
@TestMetadata("lackOfDeepIncorporation.kt")
public void testLackOfDeepIncorporation() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/lackOfDeepIncorporation.kt");
@@ -11087,6 +11087,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/callableReferences.kt");
}
@TestMetadata("fixingVariableDuringAddingConstraintForFirstPosponedArgument.kt")
public void testFixingVariableDuringAddingConstraintForFirstPosponedArgument() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/fixingVariableDuringAddingConstraintForFirstPosponedArgument.kt");
}
@TestMetadata("lackOfDeepIncorporation.kt")
public void testLackOfDeepIncorporation() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/lackOfDeepIncorporation.kt");