~ updates
diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java
index 50b3592..400ebc6 100644
--- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java
+++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java
@@ -17110,6 +17110,12 @@
}
@Test
+ @TestMetadata("assignmentUsingIncompletePCLACall.kt")
+ public void testAssignmentUsingIncompletePCLACall() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/inference/builderInference/assignmentUsingIncompletePCLACall.kt");
+ }
+
+ @Test
@TestMetadata("bothOuterAndProperConstraints.kt")
public void testBothOuterAndProperConstraints() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/bothOuterAndProperConstraints.kt");
@@ -17410,6 +17416,12 @@
}
@Test
+ @TestMetadata("singleBranchConditionLastStatementInLambda.kt")
+ public void testSingleBranchConditionLastStatementInLambda() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/inference/builderInference/singleBranchConditionLastStatementInLambda.kt");
+ }
+
+ @Test
@TestMetadata("skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt")
public void testSkipedUnresolvedInBuilderInferenceWithStubReceiverType() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt");
diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java
index daa282d..f56938e 100644
--- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java
+++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java
@@ -17110,6 +17110,12 @@
}
@Test
+ @TestMetadata("assignmentUsingIncompletePCLACall.kt")
+ public void testAssignmentUsingIncompletePCLACall() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/inference/builderInference/assignmentUsingIncompletePCLACall.kt");
+ }
+
+ @Test
@TestMetadata("bothOuterAndProperConstraints.kt")
public void testBothOuterAndProperConstraints() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/bothOuterAndProperConstraints.kt");
@@ -17410,6 +17416,12 @@
}
@Test
+ @TestMetadata("singleBranchConditionLastStatementInLambda.kt")
+ public void testSingleBranchConditionLastStatementInLambda() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/inference/builderInference/singleBranchConditionLastStatementInLambda.kt");
+ }
+
+ @Test
@TestMetadata("skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt")
public void testSkipedUnresolvedInBuilderInferenceWithStubReceiverType() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt");
diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java
index 6f20c70..fb05050 100644
--- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java
+++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java
@@ -17104,6 +17104,12 @@
}
@Test
+ @TestMetadata("assignmentUsingIncompletePCLACall.kt")
+ public void testAssignmentUsingIncompletePCLACall() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/inference/builderInference/assignmentUsingIncompletePCLACall.kt");
+ }
+
+ @Test
@TestMetadata("bothOuterAndProperConstraints.kt")
public void testBothOuterAndProperConstraints() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/bothOuterAndProperConstraints.kt");
@@ -17404,6 +17410,12 @@
}
@Test
+ @TestMetadata("singleBranchConditionLastStatementInLambda.kt")
+ public void testSingleBranchConditionLastStatementInLambda() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/inference/builderInference/singleBranchConditionLastStatementInLambda.kt");
+ }
+
+ @Test
@TestMetadata("skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt")
public void testSkipedUnresolvedInBuilderInferenceWithStubReceiverType() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt");
diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java
index a8e848c..3313b98 100644
--- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java
+++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java
@@ -17110,6 +17110,12 @@
}
@Test
+ @TestMetadata("assignmentUsingIncompletePCLACall.kt")
+ public void testAssignmentUsingIncompletePCLACall() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/inference/builderInference/assignmentUsingIncompletePCLACall.kt");
+ }
+
+ @Test
@TestMetadata("bothOuterAndProperConstraints.kt")
public void testBothOuterAndProperConstraints() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/bothOuterAndProperConstraints.kt");
@@ -17410,6 +17416,12 @@
}
@Test
+ @TestMetadata("singleBranchConditionLastStatementInLambda.kt")
+ public void testSingleBranchConditionLastStatementInLambda() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/inference/builderInference/singleBranchConditionLastStatementInLambda.kt");
+ }
+
+ @Test
@TestMetadata("skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt")
public void testSkipedUnresolvedInBuilderInferenceWithStubReceiverType() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt");
diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt
index aa2dacd..8c0776d 100644
--- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt
+++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt
@@ -37,6 +37,7 @@
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
import org.jetbrains.kotlin.types.AbstractTypeChecker
import org.jetbrains.kotlin.types.model.TypeSystemCommonSuperTypesContext
+import org.jetbrains.kotlin.types.model.safeSubstitute
import org.jetbrains.kotlin.types.model.typeConstructor
val SAM_LOOKUP_NAME = Name.special("<SAM-CONSTRUCTOR>")
@@ -167,6 +168,26 @@
}
}
+// For PCLA/Delegate inference partially completed calls, there might be a situation when
+// - There are already fixed variables (because we need them for lambda analysis)
+// - They are used in return types
+//
+// In this case, we substitute them explicitly because otherwise
+// TypeCheckerStateForConstraintInjector.fixedTypeVariable throws an exception.
+//
+// Note that this is not relevant outside PCLA context because
+// - For partial completion, we avoid fixing TVs that are used inside return types
+// - For FULL completion, we would run completion results writing, so there would be no candidates and type variables inside return types.
+//
+// See singleBranchConditionLastStatementInLambda.kt and assignmentUsingIncompletePCLACall.kt tests
+private fun ConeKotlinType.prepareTypeForPartiallyCompletedPCLACall(
+ candidate: Candidate, outerCSBuilder: ConstraintSystemBuilder
+): ConeKotlinType {
+ if (!candidate.system.usesOuterCs) return this
+
+ return outerCSBuilder.buildCurrentSubstitutor().safeSubstitute(candidate.callInfo.session.typeContext, this) as ConeKotlinType
+}
+
fun Candidate.resolveSubCallArgument(
csBuilder: ConstraintSystemBuilder,
argument: FirResolvable,
@@ -193,7 +214,7 @@
* placeholder type with value 0, but argument contains type with proper literal value
*/
val type: ConeKotlinType = context.returnTypeCalculator.tryCalculateReturnType(candidate.symbol.fir as FirCallableDeclaration).type
- val argumentType = candidate.substitutor.substituteOrSelf(type)
+ val argumentType = candidate.substitutor.substituteOrSelf(type).prepareTypeForPartiallyCompletedPCLACall(candidate, csBuilder)
resolvePlainArgumentType(
csBuilder,
argument,
diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/CompletionModeCalculator.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/CompletionModeCalculator.kt
index b126489..4afc20e 100644
--- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/CompletionModeCalculator.kt
+++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/CompletionModeCalculator.kt
@@ -33,8 +33,6 @@
// Full if return type for call has no type variables
csBuilder.isProperType(currentReturnType) -> ConstraintSystemCompletionMode.FULL
- csBuilder.usesOuterCs -> ConstraintSystemCompletionMode.PARTIAL
-
else -> CalculatorForNestedCall(
this, currentReturnType, csBuilder, components.trivialConstraintTypeInferenceOracle
).computeCompletionMode()
diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/assignmentUsingIncompletePCLACall.kt b/compiler/testData/diagnostics/tests/inference/builderInference/assignmentUsingIncompletePCLACall.kt
new file mode 100644
index 0000000..0cfc522
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/inference/builderInference/assignmentUsingIncompletePCLACall.kt
@@ -0,0 +1,20 @@
+// FIR_IDENTICAL
+
+class Controller<T> {
+ fun yield(t: T): Boolean = true
+}
+
+fun <S> generate(g: suspend Controller<S>.() -> Unit): S = TODO()
+fun <T, R> T.bar(x: (T) -> R): R = TODO()
+
+var children: String = TODO()
+
+fun main(key: String?, v: Number) {
+ generate {
+ yield("")
+ // Here, elvis-synthetic call is not completed yet, but it's variable K is already fixed
+ // Assignment is used, because for that (outside of PCLA) we would use FULL completion
+ children = key ?: v.bar { it.toString() }
+ }.length
+}
+
diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/singleBranchConditionLastStatementInLambda.kt b/compiler/testData/diagnostics/tests/inference/builderInference/singleBranchConditionLastStatementInLambda.kt
new file mode 100644
index 0000000..226cbb5
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/inference/builderInference/singleBranchConditionLastStatementInLambda.kt
@@ -0,0 +1,19 @@
+// FIR_IDENTICAL
+
+class Controller<T> {
+ fun yield(t: T): Boolean = true
+}
+
+fun <R> myRun(b: () -> R) {}
+fun <S> generate(g: suspend Controller<S>.() -> Unit): S = TODO()
+
+fun foo(b: Boolean) {
+ generate {
+ myRun {
+ if (b) {
+ yield("")
+ }
+ }
+ Unit
+ }
+}
diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java
index 5bd9c35..98bacf3 100644
--- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java
+++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java
@@ -17110,6 +17110,12 @@
}
@Test
+ @TestMetadata("assignmentUsingIncompletePCLACall.kt")
+ public void testAssignmentUsingIncompletePCLACall() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/inference/builderInference/assignmentUsingIncompletePCLACall.kt");
+ }
+
+ @Test
@TestMetadata("bothOuterAndProperConstraints.kt")
public void testBothOuterAndProperConstraints() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/bothOuterAndProperConstraints.kt");
@@ -17410,6 +17416,12 @@
}
@Test
+ @TestMetadata("singleBranchConditionLastStatementInLambda.kt")
+ public void testSingleBranchConditionLastStatementInLambda() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/inference/builderInference/singleBranchConditionLastStatementInLambda.kt");
+ }
+
+ @Test
@TestMetadata("skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt")
public void testSkipedUnresolvedInBuilderInferenceWithStubReceiverType() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt");