Extract EmptyIntersectionTypeKind.isDefinitelyEmpty to a property

This commit is contained in:
Mikhail Glukhikh
2022-12-05 10:58:04 +01:00
committed by Space Team
parent 4d01ad439a
commit 29ad5f981c
6 changed files with 18 additions and 30 deletions
@@ -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
@@ -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 {
@@ -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<KotlinType>
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)
@@ -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
@@ -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
}
}
}
@@ -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