Added isAllowedTypeVariable inside KotlinTypeChecker
This commit is contained in:
@@ -177,8 +177,12 @@ object NewKotlinTypeChecker : KotlinTypeChecker {
|
||||
}
|
||||
|
||||
private fun TypeCheckerContext.isSubtypeOfForSingleClassifierType(subType: SimpleType, superType: SimpleType): Boolean {
|
||||
assert(subType.isSingleClassifierType || subType.isIntersectionType) { "Not singleClassifierType and not intersection subType: $subType" }
|
||||
assert(superType.isSingleClassifierType) { "Not singleClassifierType superType: $superType" }
|
||||
assert(subType.isSingleClassifierType || subType.isIntersectionType || subType.isAllowedTypeVariable) {
|
||||
"Not singleClassifierType and not intersection subType: $subType"
|
||||
}
|
||||
assert(superType.isSingleClassifierType || superType.isAllowedTypeVariable) {
|
||||
"Not singleClassifierType superType: $superType"
|
||||
}
|
||||
|
||||
if (!NullabilityChecker.isPossibleSubtype(this, subType, superType)) return false
|
||||
|
||||
@@ -342,8 +346,12 @@ object NullabilityChecker {
|
||||
|
||||
private fun TypeCheckerContext.runIsPossibleSubtype(subType: SimpleType, superType: SimpleType): Boolean {
|
||||
// it makes for case String? & Any <: String
|
||||
assert(subType.isIntersectionType || subType.isSingleClassifierType) {"Not singleClassifierType superType: $superType"}
|
||||
assert(superType.isSingleClassifierType) {"Not singleClassifierType superType: $superType"}
|
||||
assert(subType.isIntersectionType || subType.isSingleClassifierType || subType.isAllowedTypeVariable) {
|
||||
"Not singleClassifierType superType: $superType"
|
||||
}
|
||||
assert(superType.isSingleClassifierType || subType.isAllowedTypeVariable) {
|
||||
"Not singleClassifierType superType: $superType"
|
||||
}
|
||||
|
||||
// superType is actually nullable
|
||||
if (superType.isMarkedNullable) return true
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.utils.SmartSet
|
||||
import java.util.*
|
||||
|
||||
open class TypeCheckerContext(val errorTypeEqualsToAnything: Boolean) {
|
||||
open class TypeCheckerContext(val errorTypeEqualsToAnything: Boolean, val allowedTypeVariable: Boolean = true) {
|
||||
protected var argumentsDepth = 0
|
||||
|
||||
private var supertypesLocked = false
|
||||
@@ -116,4 +116,6 @@ open class TypeCheckerContext(val errorTypeEqualsToAnything: Boolean) {
|
||||
substitutor.safeSubstitute(type.lowerIfFlexible(), Variance.INVARIANT).asSimpleType()
|
||||
}
|
||||
}
|
||||
|
||||
val UnwrappedType.isAllowedTypeVariable: Boolean get() = allowedTypeVariable && constructor is NewTypeVariableConstructor
|
||||
}
|
||||
@@ -100,3 +100,5 @@ private fun TypeConstructor.debugInfo() = buildString {
|
||||
declarationDescriptor = declarationDescriptor.containingDeclaration
|
||||
}
|
||||
}
|
||||
|
||||
interface NewTypeVariableConstructor
|
||||
|
||||
Reference in New Issue
Block a user