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