Remove all type system dependent methods from TypeCheckerState
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.types
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.containerRelation
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState.LowerCapturedTypePolicy.*
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState.SupertypesPolicy
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
@@ -27,7 +28,7 @@ abstract class TypeCheckerState {
|
||||
|
||||
abstract val typeSystemContext: TypeSystemContext
|
||||
|
||||
abstract fun substitutionSupertypePolicy(type: SimpleTypeMarker): SupertypesPolicy
|
||||
abstract val allowedTypeVariable: Boolean
|
||||
|
||||
@OptIn(TypeRefinement::class)
|
||||
fun refineType(type: KotlinTypeMarker): KotlinTypeMarker {
|
||||
@@ -157,10 +158,9 @@ abstract class TypeCheckerState {
|
||||
abstract class DoCustomTransform : SupertypesPolicy()
|
||||
}
|
||||
|
||||
abstract val KotlinTypeMarker.isAllowedTypeVariable: Boolean
|
||||
|
||||
@JvmName("isAllowedTypeVariableBridge")
|
||||
fun isAllowedTypeVariable(type: KotlinTypeMarker): Boolean = type.isAllowedTypeVariable
|
||||
fun isAllowedTypeVariable(type: KotlinTypeMarker): Boolean {
|
||||
return allowedTypeVariable && with(typeSystemContext) { type.isTypeVariableType() }
|
||||
}
|
||||
}
|
||||
|
||||
object AbstractTypeChecker {
|
||||
@@ -596,7 +596,7 @@ object AbstractTypeChecker {
|
||||
SupertypesPolicy.LowerIfFlexible
|
||||
}
|
||||
else -> {
|
||||
state.substitutionSupertypePolicy(current)
|
||||
state.typeSystemContext.substitutionSupertypePolicy(current)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,6 +461,10 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
|
||||
fun SimpleTypeMarker.isPrimitiveType(): Boolean
|
||||
|
||||
fun KotlinTypeMarker.getAnnotations(): List<AnnotationMarker>
|
||||
|
||||
fun substitutionSupertypePolicy(type: SimpleTypeMarker): TypeCheckerState.SupertypesPolicy
|
||||
|
||||
fun KotlinTypeMarker.isTypeVariableType(): Boolean
|
||||
}
|
||||
|
||||
enum class CaptureStatus {
|
||||
|
||||
@@ -32,7 +32,6 @@ class OverridingUtilTypeSystemContext(
|
||||
return ClassicTypeCheckerState(
|
||||
errorTypesEqualToAnything,
|
||||
stubTypesEqualToAnything,
|
||||
allowedTypeVariable = true,
|
||||
kotlinTypeRefiner,
|
||||
typeSystemContext = this
|
||||
)
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.types.model.SimpleTypeMarker
|
||||
open class ClassicTypeCheckerState(
|
||||
val errorTypeEqualsToAnything: Boolean,
|
||||
val stubTypeEqualsToAnything: Boolean = true,
|
||||
val allowedTypeVariable: Boolean = true,
|
||||
override val kotlinTypeRefiner: KotlinTypeRefiner = KotlinTypeRefiner.Default,
|
||||
override val kotlinTypePreparator: KotlinTypePreparator = KotlinTypePreparator.Default,
|
||||
override val typeSystemContext: ClassicTypeSystemContext = SimpleClassicTypeSystemContext
|
||||
@@ -34,29 +33,6 @@ open class ClassicTypeCheckerState(
|
||||
override val isStubTypeEqualsToAnything: Boolean
|
||||
get() = stubTypeEqualsToAnything
|
||||
|
||||
override fun substitutionSupertypePolicy(type: SimpleTypeMarker): SupertypesPolicy.DoCustomTransform {
|
||||
return typeSystemContext.classicSubstitutionSupertypePolicy(type)
|
||||
}
|
||||
|
||||
override val KotlinTypeMarker.isAllowedTypeVariable: Boolean get() = this is UnwrappedType && allowedTypeVariable && constructor is NewTypeVariableConstructor
|
||||
|
||||
companion object {
|
||||
fun ClassicTypeSystemContext.classicSubstitutionSupertypePolicy(type: SimpleTypeMarker): SupertypesPolicy.DoCustomTransform {
|
||||
require(type is SimpleType, type::errorMessage)
|
||||
val substitutor = TypeConstructorSubstitution.create(type).buildSubstitutor()
|
||||
|
||||
return object : SupertypesPolicy.DoCustomTransform() {
|
||||
override fun transformType(state: TypeCheckerState, type: KotlinTypeMarker): SimpleTypeMarker {
|
||||
return substitutor.safeSubstitute(
|
||||
type.lowerBoundIfFlexible() as KotlinType,
|
||||
Variance.INVARIANT
|
||||
).asSimpleType()!!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Any.errorMessage(): String {
|
||||
return "ClassicTypeCheckerContext couldn't handle ${this::class} $this"
|
||||
override val allowedTypeVariable: Boolean
|
||||
get() = true
|
||||
}
|
||||
|
||||
@@ -788,6 +788,24 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
||||
} else {
|
||||
createFlexibleType(this, this.withNullability(true))
|
||||
}
|
||||
|
||||
override fun substitutionSupertypePolicy(type: SimpleTypeMarker): TypeCheckerState.SupertypesPolicy {
|
||||
require(type is SimpleType, type::errorMessage)
|
||||
val substitutor = TypeConstructorSubstitution.create(type).buildSubstitutor()
|
||||
|
||||
return object : TypeCheckerState.SupertypesPolicy.DoCustomTransform() {
|
||||
override fun transformType(state: TypeCheckerState, type: KotlinTypeMarker): SimpleTypeMarker {
|
||||
return substitutor.safeSubstitute(
|
||||
type.lowerBoundIfFlexible() as KotlinType,
|
||||
Variance.INVARIANT
|
||||
).asSimpleType()!!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.isTypeVariableType(): Boolean {
|
||||
return this is UnwrappedType && constructor is NewTypeVariableConstructor
|
||||
}
|
||||
}
|
||||
|
||||
fun TypeVariance.convertVariance(): Variance {
|
||||
|
||||
Reference in New Issue
Block a user