From 6a343e7bffbab1be776298da7b8c4d54df89983f Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 30 Jan 2023 18:19:25 +0200 Subject: [PATCH] [FIR] Resolve forks in constraint system after analysis of postponed lambda When constraint system has forks in it usually we solve all of them before starting full completion of corresponding call. But if some call with forks was a last statement of postponed lambda, we will never call completion for it with FULL mode. Instead of it we complete it in PARTIAL mode and then just merge its constraint storage into storage of outer call. So all forks from this inner call just remain unresolved inside outer system without this fix ^KT-55966 Fixed --- ...sCompilerTestFE10TestdataTestGenerated.java | 6 ++++++ ...FirOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ ...dDiagnosticsWithLightTreeTestGenerated.java | 6 ++++++ .../inference/PostponedArgumentsAnalyzer.kt | 1 + .../PostponedArgumentsAnalyzerContext.kt | 1 + .../smartcastToStarProjection.fir.kt | 18 ++++++++++++++++++ .../smartCasts/smartcastToStarProjection.kt | 18 ++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++++ 8 files changed, 62 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/smartCasts/smartcastToStarProjection.fir.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/smartcastToStarProjection.kt 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 9ecbf51c0c3..2ba6231b456 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 @@ -29848,6 +29848,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/smartCasts/smartcastToNothingAfterCheckingForNull.kt"); } + @Test + @TestMetadata("smartcastToStarProjection.kt") + public void testSmartcastToStarProjection() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/smartcastToStarProjection.kt"); + } + @Test @TestMetadata("thisWithLabel.kt") public void testThisWithLabel() 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 c2326036ab8..9fe3b0900d1 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 @@ -29944,6 +29944,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/smartCasts/smartcastToNothingAfterCheckingForNull.kt"); } + @Test + @TestMetadata("smartcastToStarProjection.kt") + public void testSmartcastToStarProjection() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/smartcastToStarProjection.kt"); + } + @Test @TestMetadata("thisWithLabel.kt") public void testThisWithLabel() 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 e4db790015e..69bda3677fb 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 @@ -29848,6 +29848,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/smartCasts/smartcastToNothingAfterCheckingForNull.kt"); } + @Test + @TestMetadata("smartcastToStarProjection.kt") + public void testSmartcastToStarProjection() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/smartcastToStarProjection.kt"); + } + @Test @TestMetadata("thisWithLabel.kt") public void testThisWithLabel() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt index 36c7496e0bb..02b1fd7b8aa 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt @@ -213,6 +213,7 @@ class PostponedArgumentsAnalyzer( lambda.analyzed = true lambda.returnStatements = returnArguments + c.resolveForkPointsConstraints() if (inferenceSession != null) { val postponedVariables = inferenceSession.inferPostponedVariables(lambda, builder, completionMode) diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzerContext.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzerContext.kt index df82c8ef4af..68cd259a8d8 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzerContext.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/components/PostponedArgumentsAnalyzerContext.kt @@ -25,4 +25,5 @@ interface PostponedArgumentsAnalyzerContext : TypeSystemInferenceExtensionContex fun addOtherSystem(otherSystem: ConstraintStorage) fun getBuilder(): ConstraintSystemBuilder + fun resolveForkPointsConstraints() } diff --git a/compiler/testData/diagnostics/tests/smartCasts/smartcastToStarProjection.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/smartcastToStarProjection.fir.kt new file mode 100644 index 00000000000..3ad504383f6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/smartcastToStarProjection.fir.kt @@ -0,0 +1,18 @@ +// SKIP_TXT +// ISSUE: KT-55966 +// INFERENCE_HELPERS + +class Inv + +abstract class A + +fun get(e: A): T = null!! + +fun produce(producer: () -> K): K = null!! + +fun test(t: A) { + @Suppress("UNCHECKED_CAST") + t as A> + ")!>id(get(t)) + ")!>produce { get(t) } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/smartcastToStarProjection.kt b/compiler/testData/diagnostics/tests/smartCasts/smartcastToStarProjection.kt new file mode 100644 index 00000000000..7d12cf85639 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/smartcastToStarProjection.kt @@ -0,0 +1,18 @@ +// SKIP_TXT +// ISSUE: KT-55966 +// INFERENCE_HELPERS + +class Inv + +abstract class A + +fun get(e: A): T = null!! + +fun produce(producer: () -> K): K = null!! + +fun test(t: A) { + @Suppress("UNCHECKED_CAST") + t as A> + ")!>id(get(t)) + ")!>produce { get(t) } +} 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 0487c053646..123dcf9a998 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 @@ -29944,6 +29944,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/smartCasts/smartcastToNothingAfterCheckingForNull.kt"); } + @Test + @TestMetadata("smartcastToStarProjection.kt") + public void testSmartcastToStarProjection() throws Exception { + runTest("compiler/testData/diagnostics/tests/smartCasts/smartcastToStarProjection.kt"); + } + @Test @TestMetadata("thisWithLabel.kt") public void testThisWithLabel() throws Exception {