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 2ff116feed1..64cebfe3747 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 @@ -16377,6 +16377,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/covariance.kt"); } + @Test + @TestMetadata("emptyIntersectionOnIf.kt") + public void testEmptyIntersectionOnIf() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/emptyIntersectionOnIf.kt"); + } + @Test @TestMetadata("kt45461.kt") public void testKt45461() throws Exception { 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 dd084eef7eb..5480cd7baba 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 @@ -16377,6 +16377,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/covariance.kt"); } + @Test + @TestMetadata("emptyIntersectionOnIf.kt") + public void testEmptyIntersectionOnIf() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/emptyIntersectionOnIf.kt"); + } + @Test @TestMetadata("kt45461.kt") public void testKt45461() throws Exception { 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 3a740771734..de28efb7378 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 @@ -16377,6 +16377,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/covariance.kt"); } + @Test + @TestMetadata("emptyIntersectionOnIf.kt") + public void testEmptyIntersectionOnIf() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/emptyIntersectionOnIf.kt"); + } + @Test @TestMetadata("kt45461.kt") public void testKt45461() throws Exception { 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 0edecfda077..2a9f015cd00 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 @@ -16383,6 +16383,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/covariance.kt"); } + @Test + @TestMetadata("emptyIntersectionOnIf.kt") + public void testEmptyIntersectionOnIf() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/emptyIntersectionOnIf.kt"); + } + @Test @TestMetadata("kt45461.kt") public void testKt45461() throws Exception { diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/emptyIntersectionOnIf.fir.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/emptyIntersectionOnIf.fir.kt new file mode 100644 index 00000000000..97201bcfc8e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/emptyIntersectionOnIf.fir.kt @@ -0,0 +1,8 @@ +// ISSUE: KT-57649 + +open class A +abstract class B { + fun test(current: A): A? = + // K2 reports empty intersection here due to the smart cast from A to B, where A & B aren't compatible + if (current === this) current else null +} diff --git a/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/emptyIntersectionOnIf.kt b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/emptyIntersectionOnIf.kt new file mode 100644 index 00000000000..42118474bdf --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/emptyIntersectionOnIf.kt @@ -0,0 +1,8 @@ +// ISSUE: KT-57649 + +open class A +abstract class B { + fun test(current: A): A? = + // K2 reports empty intersection here due to the smart cast from A to B, where A & B aren't compatible + if (current === this) current else 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 8e089d3df89..9033b120715 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 @@ -16383,6 +16383,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/covariance.kt"); } + @Test + @TestMetadata("emptyIntersectionOnIf.kt") + public void testEmptyIntersectionOnIf() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/emptyIntersectionOnIf.kt"); + } + @Test @TestMetadata("kt45461.kt") public void testKt45461() throws Exception {