[FE 1.0] Use the new type intersection emptiness check
Also introduced compatibility mode to preserve compatibility for is/as/equality checks ^KT-29316 Related
This commit is contained in:
committed by
teamcity
parent
bc1c2adae1
commit
8227c4b603
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.isCaptured
|
||||
import org.jetbrains.kotlin.resolve.checkers.EmptyIntersectionTypeChecker
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.*
|
||||
@@ -30,6 +31,7 @@ import org.jetbrains.kotlin.types.model.TypeArgumentMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeVariableTypeConstructorMarker
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import org.jetbrains.kotlin.types.error.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
@@ -395,3 +397,8 @@ fun isUnresolvedType(type: KotlinType): Boolean {
|
||||
}
|
||||
return type is ErrorType && type.kind.isUnresolved
|
||||
}
|
||||
|
||||
fun isEmptyIntersectionTypeCompatible(vararg types: KotlinTypeMarker): Boolean =
|
||||
EmptyIntersectionTypeChecker.computeEmptyIntersectionEmptiness(
|
||||
SimpleClassicTypeSystemContext, types.toList(), compatibilityModeEnabled = true
|
||||
)?.kind == EmptyIntersectionTypeKind.COMPATIBLE
|
||||
|
||||
+15
-2
@@ -425,11 +425,10 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
||||
return when (this) {
|
||||
is SimpleTypeMarker -> this.withNullability(nullable)
|
||||
is FlexibleTypeMarker -> createFlexibleType(lowerBound().withNullability(nullable), upperBound().withNullability(nullable))
|
||||
else -> error("sealed")
|
||||
else -> asSimpleType()?.withNullability(nullable) ?: error("Unwrapped type should be simple")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun newTypeCheckerState(
|
||||
errorTypesEqualToAnything: Boolean,
|
||||
stubTypesEqualToAnything: Boolean
|
||||
@@ -478,6 +477,20 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
||||
return this.replaceAnnotations(Annotations.create(annotationsWithoutExact))
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.canHaveSubtypes(typeChecker: AbstractTypeChecker): Boolean? {
|
||||
require(this is KotlinType, this::errorMessage)
|
||||
|
||||
val kotlinTypeChecker = object : KotlinTypeChecker {
|
||||
override fun isSubtypeOf(subtype: KotlinType, supertype: KotlinType): Boolean =
|
||||
typeChecker.isSubtypeOf(this@ClassicTypeSystemContext, subtype, supertype)
|
||||
|
||||
override fun equalTypes(a: KotlinType, b: KotlinType): Boolean =
|
||||
typeChecker.equalTypes(this@ClassicTypeSystemContext, a, b)
|
||||
}
|
||||
|
||||
return TypeUtils.canHaveSubtypes(kotlinTypeChecker, this)
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.hasExactAnnotation(): Boolean {
|
||||
require(this is UnwrappedType, this::errorMessage)
|
||||
return hasExactInternal(this)
|
||||
|
||||
Reference in New Issue
Block a user