[Misc] Make NewKotlinTypeChecker non-static
This commit is contained in:
committed by
Dmitry Savvinov
parent
4f1e85b468
commit
f026a98403
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import org.jetbrains.kotlin.types.typeUtil.representativeUpperBound
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.math.max
|
||||
|
||||
interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSystemCommonBackendContext {
|
||||
override fun TypeConstructorMarker.isDenotable(): Boolean {
|
||||
@@ -427,7 +428,7 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy
|
||||
|
||||
override fun prepareType(type: KotlinTypeMarker): KotlinTypeMarker {
|
||||
require(type is UnwrappedType, type::errorMessage)
|
||||
return NewKotlinTypeChecker.transformToNewType(type)
|
||||
return NewKotlinTypeChecker.Default.transformToNewType(type)
|
||||
}
|
||||
|
||||
override fun DefinitelyNotNullTypeMarker.original(): SimpleTypeMarker {
|
||||
|
||||
@@ -114,7 +114,7 @@ object TypeIntersector {
|
||||
|
||||
IntegerLiteralTypeConstructor.findIntersectionType(filteredEqualTypes)?.let { return it }
|
||||
|
||||
val filteredSuperAndEqualTypes = filterTypes(filteredEqualTypes, NewKotlinTypeChecker::equalTypes)
|
||||
val filteredSuperAndEqualTypes = filterTypes(filteredEqualTypes, NewKotlinTypeChecker.Default::equalTypes)
|
||||
assert(filteredSuperAndEqualTypes.isNotEmpty(), errorMessage)
|
||||
|
||||
if (filteredSuperAndEqualTypes.size < 2) return filteredSuperAndEqualTypes.single()
|
||||
@@ -145,7 +145,7 @@ object TypeIntersector {
|
||||
}
|
||||
|
||||
private fun isStrictSupertype(subtype: KotlinType, supertype: KotlinType): Boolean {
|
||||
return with(NewKotlinTypeChecker) {
|
||||
return with(NewKotlinTypeChecker.Default) {
|
||||
isSubtypeOf(subtype, supertype) && !isSubtypeOf(supertype, subtype)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public interface KotlinTypeChecker {
|
||||
boolean equals(@NotNull TypeConstructor a, @NotNull TypeConstructor b);
|
||||
}
|
||||
|
||||
KotlinTypeChecker DEFAULT = NewKotlinTypeChecker.INSTANCE;
|
||||
KotlinTypeChecker DEFAULT = NewKotlinTypeChecker.Companion.getDefault();
|
||||
|
||||
boolean isSubtypeOf(@NotNull KotlinType subtype, @NotNull KotlinType supertype);
|
||||
boolean equalTypes(@NotNull KotlinType a, @NotNull KotlinType b);
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.utils.DO_NOTHING_2
|
||||
// if input type is capturedType, then we approximate it to UpperBound
|
||||
// null means that type should be leaved as is
|
||||
fun prepareArgumentTypeRegardingCaptureTypes(argumentType: UnwrappedType): UnwrappedType? {
|
||||
val simpleType = NewKotlinTypeChecker.transformToNewType(argumentType.lowerIfFlexible())
|
||||
val simpleType = NewKotlinTypeChecker.Default.transformToNewType(argumentType.lowerIfFlexible())
|
||||
if (simpleType.constructor is IntersectionTypeConstructor) {
|
||||
var changed = false
|
||||
val preparedSuperTypes = simpleType.constructor.supertypes.map {
|
||||
@@ -97,10 +97,10 @@ fun captureFromArguments(
|
||||
|
||||
if (oldProjection.projectionKind == Variance.INVARIANT) continue
|
||||
var upperBounds = type.constructor.parameters[index].upperBounds.map {
|
||||
NewKotlinTypeChecker.transformToNewType(substitutor.safeSubstitute(it, Variance.INVARIANT).unwrap())
|
||||
NewKotlinTypeChecker.Default.transformToNewType(substitutor.safeSubstitute(it, Variance.INVARIANT).unwrap())
|
||||
}
|
||||
if (!oldProjection.isStarProjection && oldProjection.projectionKind == Variance.OUT_VARIANCE) {
|
||||
upperBounds += NewKotlinTypeChecker.transformToNewType(oldProjection.type.unwrap())
|
||||
upperBounds += NewKotlinTypeChecker.Default.transformToNewType(oldProjection.type.unwrap())
|
||||
}
|
||||
|
||||
val capturedType = newProjection.type as NewCapturedType
|
||||
|
||||
@@ -49,13 +49,22 @@ object StrictEqualityTypeChecker {
|
||||
|
||||
object ErrorTypesAreEqualToAnything : KotlinTypeChecker {
|
||||
override fun isSubtypeOf(subtype: KotlinType, supertype: KotlinType): Boolean =
|
||||
NewKotlinTypeChecker.run { ClassicTypeCheckerContext(true).isSubtypeOf(subtype.unwrap(), supertype.unwrap()) }
|
||||
NewKotlinTypeChecker.Default.run { ClassicTypeCheckerContext(true).isSubtypeOf(subtype.unwrap(), supertype.unwrap()) }
|
||||
|
||||
override fun equalTypes(a: KotlinType, b: KotlinType): Boolean =
|
||||
NewKotlinTypeChecker.run { ClassicTypeCheckerContext(true).equalTypes(a.unwrap(), b.unwrap()) }
|
||||
NewKotlinTypeChecker.Default.run { ClassicTypeCheckerContext(true).equalTypes(a.unwrap(), b.unwrap()) }
|
||||
}
|
||||
|
||||
object NewKotlinTypeChecker : KotlinTypeChecker {
|
||||
interface NewKotlinTypeChecker : KotlinTypeChecker {
|
||||
fun transformToNewType(type: UnwrappedType): UnwrappedType
|
||||
|
||||
companion object {
|
||||
val Default = NewKotlinTypeCheckerImpl()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class NewKotlinTypeCheckerImpl() : NewKotlinTypeChecker {
|
||||
override fun isSubtypeOf(subtype: KotlinType, supertype: KotlinType): Boolean =
|
||||
ClassicTypeCheckerContext(true).isSubtypeOf(subtype.unwrap(), supertype.unwrap()) // todo fix flag errorTypeEqualsToAnything
|
||||
|
||||
@@ -115,7 +124,7 @@ object NewKotlinTypeChecker : KotlinTypeChecker {
|
||||
return type
|
||||
}
|
||||
|
||||
fun transformToNewType(type: UnwrappedType): UnwrappedType =
|
||||
override fun transformToNewType(type: UnwrappedType): UnwrappedType =
|
||||
when (type) {
|
||||
is SimpleType -> transformToNewType(type)
|
||||
is FlexibleType -> {
|
||||
|
||||
Reference in New Issue
Block a user