K2: add test for KT-57649
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 2ff116f..64cebfe 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
@@ -16378,6 +16378,12 @@
}
@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 {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.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 dd084ee..5480cd7 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
@@ -16378,6 +16378,12 @@
}
@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 {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.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 3a74077..de28efb 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
@@ -16378,6 +16378,12 @@
}
@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 {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.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 0edecfd..2a9f015c 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
@@ -16384,6 +16384,12 @@
}
@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 {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.kt");
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 0000000..97201bc
--- /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
+ <!INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION_WARNING("K; B?, A?; multiple incompatible classes; : B, A")!>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 0000000..4211847
--- /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 8e089d3..9033b12 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
@@ -16384,6 +16384,12 @@
}
@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 {
runTest("compiler/testData/diagnostics/tests/inference/emptyIntersectionTypes/kt45461.kt");