diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 26b7692b913..d7cd6ab71f7 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -14282,6 +14282,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/inference/smartCastForkForExpectType.kt"); } + @Test + @TestMetadata("smartCastForkForExpectedTypeNested.kt") + public void testSmartCastForkForExpectedTypeNested() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/smartCastForkForExpectedTypeNested.kt"); + } + @Test @TestMetadata("specialCallsWithCallableReferences.kt") public void testSpecialCallsWithCallableReferences() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 72997bd2a26..e77ab8629da 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -14282,6 +14282,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/smartCastForkForExpectType.kt"); } + @Test + @TestMetadata("smartCastForkForExpectedTypeNested.kt") + public void testSmartCastForkForExpectedTypeNested() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/smartCastForkForExpectedTypeNested.kt"); + } + @Test @TestMetadata("specialCallsWithCallableReferences.kt") public void testSpecialCallsWithCallableReferences() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 465c6affc41..d86b00ff448 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -14282,6 +14282,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/smartCastForkForExpectType.kt"); } + @Test + @TestMetadata("smartCastForkForExpectedTypeNested.kt") + public void testSmartCastForkForExpectedTypeNested() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/smartCastForkForExpectedTypeNested.kt"); + } + @Test @TestMetadata("specialCallsWithCallableReferences.kt") public void testSpecialCallsWithCallableReferences() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt index 681241c2074..2a7edd5682b 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/ConstraintSystemCompleter.kt @@ -62,7 +62,9 @@ class ConstraintSystemCompleter(components: BodyResolveComponents, private val c ) { val topLevelTypeVariables = topLevelType.extractTypeVariables() - resolveForkPointsConstraints() + if (completionMode == ConstraintSystemCompletionMode.FULL) { + resolveForkPointsConstraints() + } completion@ while (true) { // TODO: This is very slow diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt index b324dbf9480..41b97d8815e 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt @@ -276,6 +276,7 @@ class NewConstraintSystemImpl( storage.errors.addAll(otherSystem.errors) storage.fixedTypeVariables.putAll(otherSystem.fixedTypeVariables) storage.postponedTypeVariables.addAll(otherSystem.postponedTypeVariables) + storage.constraintsFromAllForkPoints.addAll(otherSystem.constraintsFromAllForkPoints) } // ResultTypeResolver.Context, ConstraintSystemBuilder diff --git a/compiler/testData/diagnostics/tests/inference/smartCastForkForExpectedTypeNested.fir.kt b/compiler/testData/diagnostics/tests/inference/smartCastForkForExpectedTypeNested.fir.kt new file mode 100644 index 00000000000..e89a90e71c6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/smartCastForkForExpectedTypeNested.fir.kt @@ -0,0 +1,30 @@ +// SKIP_TXT + +interface Slice + +interface A +interface B : A +interface C : A + +val SL0: Slice = TODO() +val SL1: Slice = TODO() +val SL2: Slice = TODO() + +fun foo(s: Slice): X? { + if (s.hashCode() == 0) { + return id(bar(s)) + } + + if (s === SL0) { + return id(bar(s)) + } + + if (s === SL1 || s === SL2) { + return id(bar(s)) + } + return null +} + +fun id(x: T): T = x + +fun bar(w: Slice): Y? = null diff --git a/compiler/testData/diagnostics/tests/inference/smartCastForkForExpectedTypeNested.kt b/compiler/testData/diagnostics/tests/inference/smartCastForkForExpectedTypeNested.kt new file mode 100644 index 00000000000..bbd6f0c0ee8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/smartCastForkForExpectedTypeNested.kt @@ -0,0 +1,30 @@ +// SKIP_TXT + +interface Slice + +interface A +interface B : A +interface C : A + +val SL0: Slice = TODO() +val SL1: Slice = TODO() +val SL2: Slice = TODO() + +fun foo(s: Slice): X? { + if (s.hashCode() == 0) { + return id(bar(s)) + } + + if (s === SL0) { + return id(bar(s)) + } + + if (s === SL1 || s === SL2) { + return id(bar(s)) + } + return null +} + +fun id(x: T): T = x + +fun bar(w: Slice): Y? = null 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 afeb692a1f5..64feb469317 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 @@ -14288,6 +14288,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/smartCastForkForExpectType.kt"); } + @Test + @TestMetadata("smartCastForkForExpectedTypeNested.kt") + public void testSmartCastForkForExpectedTypeNested() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/smartCastForkForExpectedTypeNested.kt"); + } + @Test @TestMetadata("specialCallsWithCallableReferences.kt") public void testSpecialCallsWithCallableReferences() throws Exception {