[NI] Refine nullability for CST of types with undefined nullability
This commit is contained in:
@@ -20,9 +20,9 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.checker.NewCapturedType
|
||||
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor
|
||||
import org.jetbrains.kotlin.types.checker.NullabilityChecker
|
||||
import org.jetbrains.kotlin.types.typeUtil.canHaveUndefinedNullability
|
||||
|
||||
abstract class DelegatingSimpleType : SimpleType() {
|
||||
protected abstract val delegate: SimpleType
|
||||
@@ -82,12 +82,7 @@ class DefinitelyNotNullType private constructor(val original: SimpleType) : Dele
|
||||
}
|
||||
|
||||
fun makesSenseToBeDefinitelyNotNull(type: UnwrappedType): Boolean =
|
||||
canHaveUndefinedNullability(type) && !NullabilityChecker.isSubtypeOfAny(type)
|
||||
|
||||
private fun canHaveUndefinedNullability(type: UnwrappedType): Boolean =
|
||||
type.constructor is NewTypeVariableConstructor ||
|
||||
type.constructor.declarationDescriptor is TypeParameterDescriptor ||
|
||||
type is NewCapturedType
|
||||
type.canHaveUndefinedNullability() && !NullabilityChecker.isSubtypeOfAny(type)
|
||||
}
|
||||
|
||||
override val delegate: SimpleType
|
||||
|
||||
@@ -23,6 +23,8 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.isCaptured
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.checker.NewCapturedType
|
||||
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor
|
||||
import java.util.*
|
||||
|
||||
enum class TypeNullability {
|
||||
@@ -201,3 +203,8 @@ fun KotlinType.containsTypeProjectionsInTopLevelArguments(): Boolean {
|
||||
val possiblyInnerType = buildPossiblyInnerType() ?: return false
|
||||
return possiblyInnerType.arguments.any { it.isStarProjection || it.projectionKind != Variance.INVARIANT }
|
||||
}
|
||||
|
||||
fun UnwrappedType.canHaveUndefinedNullability(): Boolean =
|
||||
constructor is NewTypeVariableConstructor ||
|
||||
constructor.declarationDescriptor is TypeParameterDescriptor ||
|
||||
this is NewCapturedType
|
||||
|
||||
@@ -398,6 +398,9 @@ object NullabilityChecker {
|
||||
fun isSubtypeOfAny(type: UnwrappedType): Boolean =
|
||||
TypeCheckerContext(false).hasNotNullSupertype(type.lowerIfFlexible(), SupertypesPolicy.LowerIfFlexible)
|
||||
|
||||
fun hasPathByNotMarkedNullableNodes(start: SimpleType, end: TypeConstructor) =
|
||||
TypeCheckerContext(false).hasPathByNotMarkedNullableNodes(start, end)
|
||||
|
||||
private fun TypeCheckerContext.runIsPossibleSubtype(subType: SimpleType, superType: SimpleType): Boolean {
|
||||
// it makes for case String? & Any <: String
|
||||
assert(subType.isIntersectionType || subType.isSingleClassifierType || subType.isAllowedTypeVariable) {
|
||||
|
||||
Reference in New Issue
Block a user