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 e0ccedaa0a6..af8283a2190 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 @@ -13670,6 +13670,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/discardInapplicableCandidateWithNotSatisfyingSelfType.kt"); } + @Test + @TestMetadata("dontThrowEmptyIntersectionException.kt") + public void testDontThrowEmptyIntersectionException() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/dontThrowEmptyIntersectionException.kt"); + } + @Test @TestMetadata("equalitySubstitutionInsideNonInvariantType.kt") public void testEqualitySubstitutionInsideNonInvariantType() 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 8c559386300..560120ff045 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 @@ -13670,6 +13670,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/discardInapplicableCandidateWithNotSatisfyingSelfType.kt"); } + @Test + @TestMetadata("dontThrowEmptyIntersectionException.kt") + public void testDontThrowEmptyIntersectionException() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/dontThrowEmptyIntersectionException.kt"); + } + @Test @TestMetadata("equalitySubstitutionInsideNonInvariantType.kt") public void testEqualitySubstitutionInsideNonInvariantType() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/TypeIntersector.java b/compiler/frontend/src/org/jetbrains/kotlin/types/TypeIntersector.java index fdaa9af8969..7983cf24bd1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/TypeIntersector.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/TypeIntersector.java @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilderImpl; import org.jetbrains.kotlin.types.checker.KotlinTypeChecker; import org.jetbrains.kotlin.types.error.ErrorTypeKind; import org.jetbrains.kotlin.types.error.ErrorUtils; +import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt; import java.util.*; @@ -124,7 +125,7 @@ public class TypeIntersector { } if (bestRepresentative == null) { - throw new AssertionError("Empty intersection for types " + types); + return null; } return TypeUtils.makeNullableAsSpecified(bestRepresentative, allNullable); } diff --git a/compiler/testData/diagnostics/tests/inference/dontThrowEmptyIntersectionException.fir.kt b/compiler/testData/diagnostics/tests/inference/dontThrowEmptyIntersectionException.fir.kt new file mode 100644 index 00000000000..6e21807d07c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/dontThrowEmptyIntersectionException.fir.kt @@ -0,0 +1,22 @@ +// WITH_STDLIB + +// FILE: Test.java +public interface Test implements I {} + +// FILE: Test2.java +public interface Test2 + +// FILE: Test3.java +public interface Test3 {} + +// FILE: I.java +public interface I {} + +// FILE: main.kt +fun main(z: I) { + z as Test> + z as TestFoo>> + z as Test<Foo> + z as Any2 + println(z) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/dontThrowEmptyIntersectionException.kt b/compiler/testData/diagnostics/tests/inference/dontThrowEmptyIntersectionException.kt new file mode 100644 index 00000000000..e7f25b2b29e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/dontThrowEmptyIntersectionException.kt @@ -0,0 +1,22 @@ +// WITH_STDLIB + +// FILE: Test.java +public interface Test implements I {} + +// FILE: Test2.java +public interface Test2 + +// FILE: Test3.java +public interface Test3 {} + +// FILE: I.java +public interface I {} + +// FILE: main.kt +fun main(z: I) { + z as Test> + z as TestFoo>> + z as Test<Foo> + z as Any2 + println(z) +} diff --git a/compiler/testData/diagnostics/tests/inference/dontThrowEmptyIntersectionException.txt b/compiler/testData/diagnostics/tests/inference/dontThrowEmptyIntersectionException.txt new file mode 100644 index 00000000000..67d09f17f5b --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/dontThrowEmptyIntersectionException.txt @@ -0,0 +1,27 @@ +package + +public fun main(/*0*/ z: I): kotlin.Unit + +public interface I { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Test : I { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Test2 { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface Test3 { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} 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 3f6283b45c3..6b5bdda878d 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 @@ -13676,6 +13676,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/discardInapplicableCandidateWithNotSatisfyingSelfType.kt"); } + @Test + @TestMetadata("dontThrowEmptyIntersectionException.kt") + public void testDontThrowEmptyIntersectionException() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/dontThrowEmptyIntersectionException.kt"); + } + @Test @TestMetadata("equalitySubstitutionInsideNonInvariantType.kt") public void testEqualitySubstitutionInsideNonInvariantType() throws Exception {