diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index 195043f4718..6e30525b945 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -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"); diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt index e99355c484a..d9f7dbde3fd 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.types.model.TypeVariableMarker interface ConstraintSystemCompletionContext : VariableFixationFinder.Context, ResultTypeResolver.Context { val allTypeVariables: Map override val notFixedTypeVariables: Map + override val fixedTypeVariables: Map override val postponedTypeVariables: List fun getBuilder(): ConstraintSystemBuilder diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt index 49fad366a6b..618b29e8d6d 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/VariableFixationFinder.kt @@ -20,6 +20,7 @@ class VariableFixationFinder( ) { interface Context : TypeSystemInferenceExtensionContext { val notFixedTypeVariables: Map + val fixedTypeVariables: Map val postponedTypeVariables: List fun isReified(variable: TypeVariableMarker): Boolean } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/PostponedArgumentInputTypesResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/PostponedArgumentInputTypesResolver.kt index 3fc40ec10d3..2187996d44c 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/PostponedArgumentInputTypesResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/PostponedArgumentInputTypesResolver.kt @@ -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() } } diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/fixingVariableDuringAddingConstraintForFirstPosponedArgument.kt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/fixingVariableDuringAddingConstraintForFirstPosponedArgument.kt new file mode 100644 index 00000000000..670c71482ab --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/fixingVariableDuringAddingConstraintForFirstPosponedArgument.kt @@ -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 -> { } }) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/fixingVariableDuringAddingConstraintForFirstPosponedArgument.txt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/fixingVariableDuringAddingConstraintForFirstPosponedArgument.txt new file mode 100644 index 00000000000..2f52c066a12 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/fixingVariableDuringAddingConstraintForFirstPosponedArgument.txt @@ -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 diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 0d171e649b0..be7d38c0a43 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index b48fa166fd4..e504725bcc5 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -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");