diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index febf4f949ea..ea5c05149c7 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -9866,6 +9866,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/inference/coerceFunctionLiteralToSuspend.kt"); } + @TestMetadata("commonSuperTypeOfErrorTypes.kt") + public void testCommonSuperTypeOfErrorTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/commonSuperTypeOfErrorTypes.kt"); + } + @TestMetadata("completeInferenceIfManyFailed.kt") public void testCompleteInferenceIfManyFailed() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.kt"); diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt index 1ca3cd7c2d4..464a348ad05 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.types.AbstractFlexibilityChecker.hasDifferentFlexibi import org.jetbrains.kotlin.types.AbstractNullabilityChecker.hasPathByNotMarkedNullableNodes import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext import org.jetbrains.kotlin.types.model.* +import org.jetbrains.kotlin.utils.addToStdlib.safeAs object NewCommonSuperTypeCalculator { // TODO: Bridge for old calls @@ -96,6 +97,10 @@ object NewCommonSuperTypeCalculator { contextStubTypesEqualToAnything: AbstractTypeCheckerContext, contextStubTypesNotEqual: AbstractTypeCheckerContext ): SimpleTypeMarker { + if (types.all { it is ErrorType }) { + return ErrorUtils.createErrorType("CST(${types.joinToString()}") + } + // i.e. result type also should be marked nullable val notAllNotNull = types.any { !isStubRelatedType(it) && !AbstractNullabilityChecker.isSubtypeOfAny(contextStubTypesEqualToAnything, it) } diff --git a/compiler/testData/diagnostics/tests/inference/commonSuperTypeOfErrorTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/commonSuperTypeOfErrorTypes.fir.kt new file mode 100644 index 00000000000..f338b2039e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSuperTypeOfErrorTypes.fir.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNCHECKED_CAST + +class Foo +class Bar + +fun consume(x: Foo, y: Foo) {} +fun materialize() = null as T + +fun test() { + consume( + materialize>>(), + materialize>>() + ) + + consume( + materialize>>(), + materialize>() + ) + +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSuperTypeOfErrorTypes.kt b/compiler/testData/diagnostics/tests/inference/commonSuperTypeOfErrorTypes.kt new file mode 100644 index 00000000000..69f584fe8ef --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSuperTypeOfErrorTypes.kt @@ -0,0 +1,21 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNCHECKED_CAST + +class Foo +class Bar + +fun consume(x: Foo, y: Foo) {} +fun materialize() = null as T + +fun test() { + consume( + materializeErrorType>>>(), + materializeErrorType>>>() + ) + + consume( + materializeErrorType>>>(), + materializeErrorType>>() + ) + +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSuperTypeOfErrorTypes.txt b/compiler/testData/diagnostics/tests/inference/commonSuperTypeOfErrorTypes.txt new file mode 100644 index 00000000000..8ddb712650a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSuperTypeOfErrorTypes.txt @@ -0,0 +1,19 @@ +package + +public fun consume(/*0*/ x: Foo, /*1*/ y: Foo): kotlin.Unit +public fun materialize(): T +public fun test(): kotlin.Unit + +public final class Bar { + public constructor Bar() + 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 final class Foo { + public constructor Foo() + 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/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index a52809c538a..66a4f9f5ad0 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -9873,6 +9873,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/inference/coerceFunctionLiteralToSuspend.kt"); } + @TestMetadata("commonSuperTypeOfErrorTypes.kt") + public void testCommonSuperTypeOfErrorTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/commonSuperTypeOfErrorTypes.kt"); + } + @TestMetadata("completeInferenceIfManyFailed.kt") public void testCompleteInferenceIfManyFailed() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 4e8e5a7ddc0..22764a5d6a7 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -9868,6 +9868,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/inference/coerceFunctionLiteralToSuspend.kt"); } + @TestMetadata("commonSuperTypeOfErrorTypes.kt") + public void testCommonSuperTypeOfErrorTypes() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/commonSuperTypeOfErrorTypes.kt"); + } + @TestMetadata("completeInferenceIfManyFailed.kt") public void testCompleteInferenceIfManyFailed() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/completeInferenceIfManyFailed.kt");