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 eb868d66849..1c1cd76669b 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 @@ -15912,6 +15912,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/inference/intersectionTypeMultipleBoundsAsReceiver.kt"); } + @Test + @TestMetadata("intersectionTypeOnWhenCall.kt") + public void testIntersectionTypeOnWhenCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/intersectionTypeOnWhenCall.kt"); + } + @Test @TestMetadata("intersectionTypesWithContravariantTypes.kt") public void testIntersectionTypesWithContravariantTypes() 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 26d5f381ea0..1e6ccf602a8 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 @@ -15912,6 +15912,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/inference/intersectionTypeMultipleBoundsAsReceiver.kt"); } + @Test + @TestMetadata("intersectionTypeOnWhenCall.kt") + public void testIntersectionTypeOnWhenCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/intersectionTypeOnWhenCall.kt"); + } + @Test @TestMetadata("intersectionTypesWithContravariantTypes.kt") public void testIntersectionTypesWithContravariantTypes() 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 f7886f2cee7..755686c3561 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 @@ -15906,6 +15906,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/inference/intersectionTypeMultipleBoundsAsReceiver.kt"); } + @Test + @TestMetadata("intersectionTypeOnWhenCall.kt") + public void testIntersectionTypeOnWhenCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/intersectionTypeOnWhenCall.kt"); + } + @Test @TestMetadata("intersectionTypesWithContravariantTypes.kt") public void testIntersectionTypesWithContravariantTypes() 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 8a54b886c33..754e7c8375e 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 @@ -15912,6 +15912,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/inference/intersectionTypeMultipleBoundsAsReceiver.kt"); } + @Test + @TestMetadata("intersectionTypeOnWhenCall.kt") + public void testIntersectionTypeOnWhenCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/intersectionTypeOnWhenCall.kt"); + } + @Test @TestMetadata("intersectionTypesWithContravariantTypes.kt") public void testIntersectionTypesWithContravariantTypes() throws Exception { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt index 88b0aac8298..585f8b561c6 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt @@ -95,9 +95,16 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo nullable, coneAttributes ) + is ConeIntersectionType -> if (coneAttributes === constructor.attributes) { + constructor + } else { + ConeIntersectionType( + constructor.intersectedTypes.map { it.withAttributes(coneAttributes) }, + constructor.alternativeType?.withAttributes(coneAttributes) + ) + } else -> error("!") } - } override fun createTypeArgument(type: KotlinTypeMarker, variance: TypeVariance): TypeArgumentMarker { diff --git a/compiler/testData/diagnostics/tests/inference/intersectionTypeOnWhenCall.kt b/compiler/testData/diagnostics/tests/inference/intersectionTypeOnWhenCall.kt new file mode 100644 index 00000000000..de6de431279 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/intersectionTypeOnWhenCall.kt @@ -0,0 +1,16 @@ +// FIR_IDENTICAL +// ISSUE: KT-62819 + +class A + +fun foo(cond: Boolean) { + val first = when (cond) { + true -> A() + false -> A() + } + + val second = when (cond) { + true -> first + false -> first + } +} \ No newline at end of file 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 e35f43348d9..429fb336cde 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 @@ -15912,6 +15912,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/intersectionTypeMultipleBoundsAsReceiver.kt"); } + @Test + @TestMetadata("intersectionTypeOnWhenCall.kt") + public void testIntersectionTypeOnWhenCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/intersectionTypeOnWhenCall.kt"); + } + @Test @TestMetadata("intersectionTypesWithContravariantTypes.kt") public void testIntersectionTypesWithContravariantTypes() throws Exception {