diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index 48a67146948..80bbec90347 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -35,7 +35,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability import org.jetbrains.kotlin.resolve.calls.tower.isSuccess import org.jetbrains.kotlin.types.EmptyIntersectionTypeKind -import org.jetbrains.kotlin.types.isPossiblyEmpty import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance import org.jetbrains.kotlin.utils.addToStdlib.runIf @@ -468,8 +467,8 @@ private fun reportInferredIntoEmptyIntersectionError( ?: typeVariable.toString() val causingTypesText = if (incompatibleTypes == causingTypes) "" else ": ${causingTypes.joinToString()}" val factory = - if (kind.isPossiblyEmpty()) FirErrors.INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION - else FirErrors.INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION + if (kind.isDefinitelyEmpty) FirErrors.INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION + else FirErrors.INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION return factory.createOn(source, typeVariableText, incompatibleTypes, kind.description, causingTypesText) } @@ -478,7 +477,6 @@ private val NewConstraintError.lowerConeType: ConeKotlinType get() = lowerType a private val NewConstraintError.upperConeType: ConeKotlinType get() = upperType as ConeKotlinType private fun ConeSimpleDiagnostic.getFactory(source: KtSourceElement): KtDiagnosticFactory0 { - @Suppress("UNCHECKED_CAST") return when (kind) { DiagnosticKind.Syntax -> FirSyntaxErrors.SYNTAX DiagnosticKind.ReturnNotAllowed -> FirErrors.RETURN_NOT_ALLOWED diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index 5e9dc05e217..02cde021c5f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -55,7 +55,6 @@ import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability import org.jetbrains.kotlin.resolve.calls.tower.isSuccess import org.jetbrains.kotlin.types.TypeApproximatorConfiguration import org.jetbrains.kotlin.types.Variance -import org.jetbrains.kotlin.types.isDefinitelyEmpty import org.jetbrains.kotlin.utils.addToStdlib.runIf import kotlin.collections.component1 import kotlin.collections.component2 @@ -848,7 +847,7 @@ class FirCallCompletionResultsWriterTransformer( } private fun FirNamedReferenceWithCandidate.hasAdditionalResolutionErrors(): Boolean = - candidate.system.errors.any { it is InferredEmptyIntersection && it.kind.isDefinitelyEmpty() } + candidate.system.errors.any { it is InferredEmptyIntersection && it.kind.isDefinitelyEmpty } private fun FirNamedReferenceWithCandidate.toResolvedReference(): FirNamedReference { val errorDiagnostic = when { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt index b3e8aa3c575..456acb5adb8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -44,7 +44,6 @@ import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.checker.intersectWrappedTypes import org.jetbrains.kotlin.types.error.ErrorUtils import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils -import org.jetbrains.kotlin.types.isPossiblyEmpty import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContextDelegate import org.jetbrains.kotlin.types.model.TypeVariableMarker import org.jetbrains.kotlin.types.model.freshTypeConstructor @@ -668,15 +667,16 @@ class DiagnosticReporterByTrackingStrategy( @Suppress("UNCHECKED_CAST") val causingTypes = error.causingTypes as List val causingTypesText = if (incompatibleTypes == causingTypes) "" else ": ${causingTypes.joinToString()}" - val diagnostic = if (error.kind.isPossiblyEmpty()) { - INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION.on( - expression, typeVariableText, incompatibleTypes, error.kind.description, causingTypesText - ) - } else { + val diagnostic = if (error.kind.isDefinitelyEmpty) { INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION.on( context.languageVersionSettings, expression, typeVariableText, incompatibleTypes, error.kind.description, causingTypesText ) + } else { + INFERRED_TYPE_VARIABLE_INTO_POSSIBLE_EMPTY_INTERSECTION.on( + expression, typeVariableText, + incompatibleTypes, error.kind.description, causingTypesText + ) } trace.reportDiagnosticOnce(diagnostic) diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt index 45ab1b71f8c..a47f80ad758 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt @@ -14,7 +14,6 @@ import org.jetbrains.kotlin.resolve.checkers.EmptyIntersectionTypeInfo import org.jetbrains.kotlin.types.AbstractTypeApproximator import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.types.TypeApproximatorConfiguration -import org.jetbrains.kotlin.types.isDefinitelyEmpty import org.jetbrains.kotlin.types.model.* import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.kotlin.utils.SmartSet @@ -519,7 +518,7 @@ class NewConstraintSystemImpl( val isInferredEmptyIntersectionForbidden = languageVersionSettings.supportsFeature(LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection) - val errorFactory = if (emptyIntersectionTypeInfo.kind.isDefinitelyEmpty() && isInferredEmptyIntersectionForbidden) + val errorFactory = if (emptyIntersectionTypeInfo.kind.isDefinitelyEmpty && isInferredEmptyIntersectionForbidden) ::InferredEmptyIntersectionError else ::InferredEmptyIntersectionWarning diff --git a/core/compiler.common/src/org/jetbrains/kotlin/resolve/checkers/EmptyIntersectionTypeChecker.kt b/core/compiler.common/src/org/jetbrains/kotlin/resolve/checkers/EmptyIntersectionTypeChecker.kt index 34c8a6a5a03..20a1ffdcec5 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/resolve/checkers/EmptyIntersectionTypeChecker.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/resolve/checkers/EmptyIntersectionTypeChecker.kt @@ -7,8 +7,6 @@ package org.jetbrains.kotlin.resolve.checkers import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.types.EmptyIntersectionTypeKind -import org.jetbrains.kotlin.types.isDefinitelyEmpty -import org.jetbrains.kotlin.types.isPossiblyEmpty import org.jetbrains.kotlin.types.TypeCheckerState import org.jetbrains.kotlin.types.model.* @@ -41,11 +39,13 @@ internal object EmptyIntersectionTypeChecker { val typeInfo = computeByHavingCommonSubtype(firstSubstitutedType, secondSubstitutedType) ?: continue - if (typeInfo.kind.isDefinitelyEmpty()) + if (typeInfo.kind.isDefinitelyEmpty) { return typeInfo + } - if (typeInfo.kind.isPossiblyEmpty()) + if (!typeInfo.kind.isDefinitelyEmpty) { possibleEmptyIntersectionTypeInfo = typeInfo + } } } diff --git a/core/compiler.common/src/org/jetbrains/kotlin/types/EmptyIntersectionTypeKind.kt b/core/compiler.common/src/org/jetbrains/kotlin/types/EmptyIntersectionTypeKind.kt index cc0e2e451bf..51f671322ed 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/types/EmptyIntersectionTypeKind.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/types/EmptyIntersectionTypeKind.kt @@ -5,16 +5,8 @@ package org.jetbrains.kotlin.types -enum class EmptyIntersectionTypeKind(val description: String) { - MULTIPLE_CLASSES("multiple incompatible classes"), - INCOMPATIBLE_SUPERTYPES("incompatible supertypes"), - INCOMPATIBLE_TYPE_ARGUMENTS("incompatible type arguments"), - FINAL_CLASS_AND_INTERFACE("final class and interface") +enum class EmptyIntersectionTypeKind(val description: String, val isDefinitelyEmpty: Boolean) { + MULTIPLE_CLASSES("multiple incompatible classes", isDefinitelyEmpty = true), + INCOMPATIBLE_SUPERTYPES("incompatible supertypes", isDefinitelyEmpty = true), + FINAL_CLASS_AND_INTERFACE("final class and interface", isDefinitelyEmpty = false) } - -fun EmptyIntersectionTypeKind.isDefinitelyEmpty(): Boolean = - this == EmptyIntersectionTypeKind.MULTIPLE_CLASSES - || this == EmptyIntersectionTypeKind.INCOMPATIBLE_SUPERTYPES - || this == EmptyIntersectionTypeKind.INCOMPATIBLE_TYPE_ARGUMENTS - -fun EmptyIntersectionTypeKind.isPossiblyEmpty(): Boolean = this == EmptyIntersectionTypeKind.FINAL_CLASS_AND_INTERFACE