Pull isNullableType and related extensions up into TypeSystemContext
This commit is contained in:
-15
@@ -256,21 +256,6 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext,
|
||||
return this.constructor.projection
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.isNullableType(): Boolean {
|
||||
require(this is ConeKotlinType)
|
||||
if (this.isMarkedNullable)
|
||||
return true
|
||||
|
||||
if (this is ConeFlexibleType && this.upperBound.isNullableType())
|
||||
return true
|
||||
|
||||
if (this is ConeTypeParameterType /* || is TypeVariable */)
|
||||
return hasNullableSuperType(type)
|
||||
|
||||
// TODO: Intersection types
|
||||
return false
|
||||
}
|
||||
|
||||
override fun DefinitelyNotNullTypeMarker.original(): SimpleTypeMarker {
|
||||
require(this is ConeDefinitelyNotNullType)
|
||||
return this.original()
|
||||
|
||||
@@ -6,19 +6,26 @@
|
||||
package org.jetbrains.kotlin.fir.resolve.calls
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.resolve.*
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
|
||||
import org.jetbrains.kotlin.fir.symbols.*
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintIncorporator
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ResultTypeResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.TrivialConstraintTypeInferenceOracle
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
|
||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContextDelegate
|
||||
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeVariableTypeConstructorMarker
|
||||
|
||||
|
||||
fun ConeInferenceContext.hasNullableSuperType(type: ConeKotlinType): Boolean {
|
||||
fun ConeTypeContext.hasNullableSuperType(type: ConeKotlinType): Boolean {
|
||||
if (type is ConeClassLikeType) return false
|
||||
|
||||
if (type !is ConeLookupTagBasedType) return false // TODO?
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.declarations.expandedConeType
|
||||
import org.jetbrains.kotlin.fir.declarations.superConeTypes
|
||||
import org.jetbrains.kotlin.fir.resolve.*
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ConeTypeVariableTypeConstructor
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.hasNullableSuperType
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutorByMap
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.firUnsafe
|
||||
@@ -28,7 +29,6 @@ import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.types.checker.convertVariance
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
|
||||
|
||||
class ErrorTypeConstructor(reason: String) : TypeConstructorMarker
|
||||
|
||||
interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext {
|
||||
@@ -408,6 +408,21 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext {
|
||||
else -> type
|
||||
}
|
||||
}
|
||||
|
||||
override fun KotlinTypeMarker.isNullableType(): Boolean {
|
||||
require(this is ConeKotlinType)
|
||||
if (this.isMarkedNullable)
|
||||
return true
|
||||
|
||||
if (this is ConeFlexibleType && this.upperBound.isNullableType())
|
||||
return true
|
||||
|
||||
if (this is ConeTypeParameterType /* || is TypeVariable */)
|
||||
return hasNullableSuperType(type)
|
||||
|
||||
// TODO: Intersection types
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
class ConeTypeCheckerContext(override val isErrorTypeEqualsToAnything: Boolean, override val session: FirSession) :
|
||||
|
||||
@@ -127,12 +127,6 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
|
||||
fun CapturedTypeMarker.typeConstructorProjection(): TypeArgumentMarker
|
||||
fun CapturedTypeMarker.captureStatus(): CaptureStatus
|
||||
|
||||
fun KotlinTypeMarker.isNullableType(): Boolean
|
||||
|
||||
fun KotlinTypeMarker.isNullableAny() = this.typeConstructor().isAnyConstructor() && this.isNullableType()
|
||||
fun KotlinTypeMarker.isNothing() = this.typeConstructor().isNothingConstructor() && !this.isNullableType()
|
||||
fun KotlinTypeMarker.isNullableNothing() = this.typeConstructor().isNothingConstructor() && this.isNullableType()
|
||||
|
||||
fun DefinitelyNotNullTypeMarker.original(): SimpleTypeMarker
|
||||
|
||||
fun typeSubstitutorByTypeConstructor(map: Map<TypeConstructorMarker, KotlinTypeMarker>): TypeSubstitutorMarker
|
||||
@@ -217,6 +211,12 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
|
||||
fun KotlinTypeMarker.typeConstructor(): TypeConstructorMarker =
|
||||
(asSimpleType() ?: lowerBoundIfFlexible()).typeConstructor()
|
||||
|
||||
fun KotlinTypeMarker.isNullableType(): Boolean
|
||||
|
||||
fun KotlinTypeMarker.isNullableAny() = this.typeConstructor().isAnyConstructor() && this.isNullableType()
|
||||
fun KotlinTypeMarker.isNothing() = this.typeConstructor().isNothingConstructor() && !this.isNullableType()
|
||||
fun KotlinTypeMarker.isNullableNothing() = this.typeConstructor().isNothingConstructor() && this.isNullableType()
|
||||
|
||||
fun SimpleTypeMarker.isClassType(): Boolean = typeConstructor().isClassTypeConstructor()
|
||||
|
||||
fun SimpleTypeMarker.fastCorrespondingSupertypes(constructor: TypeConstructorMarker): List<SimpleTypeMarker>? = null
|
||||
|
||||
Reference in New Issue
Block a user