Integrate nullability into cone types, add & use FIR flexible type
FIR fake overrides are rendered now more precisely to test this process
This commit is contained in:
@@ -40,6 +40,18 @@ class ConeKotlinTypeProjectionOut(override val type: ConeKotlinType) : ConeKotli
|
||||
get() = ProjectionKind.OUT
|
||||
}
|
||||
|
||||
enum class ConeNullability(val suffix: String) {
|
||||
NULLABLE("?"),
|
||||
UNKNOWN("!"),
|
||||
NOT_NULL("");
|
||||
|
||||
val isNullable: Boolean get() = this != NOT_NULL
|
||||
|
||||
companion object {
|
||||
fun create(isNullable: Boolean) = if (isNullable) NULLABLE else NOT_NULL
|
||||
}
|
||||
}
|
||||
|
||||
// We assume type IS an invariant type projection to prevent additional wrapper here
|
||||
// (more exactly, invariant type projection contains type)
|
||||
sealed class ConeKotlinType : ConeKotlinTypeProjection(), ConeTypedProjection {
|
||||
@@ -50,12 +62,17 @@ sealed class ConeKotlinType : ConeKotlinTypeProjection(), ConeTypedProjection {
|
||||
|
||||
override val type: ConeKotlinType
|
||||
get() = this
|
||||
|
||||
abstract val nullability: ConeNullability
|
||||
}
|
||||
|
||||
class ConeKotlinErrorType(val reason: String) : ConeKotlinType() {
|
||||
override val typeArguments: Array<out ConeKotlinTypeProjection>
|
||||
get() = EMPTY_ARRAY
|
||||
|
||||
override val nullability: ConeNullability
|
||||
get() = ConeNullability.UNKNOWN
|
||||
|
||||
override fun toString(): String {
|
||||
return "<ERROR TYPE: $reason>"
|
||||
}
|
||||
@@ -68,6 +85,9 @@ class ConeClassErrorType(val reason: String) : ConeClassLikeType() {
|
||||
override val typeArguments: Array<out ConeKotlinTypeProjection>
|
||||
get() = EMPTY_ARRAY
|
||||
|
||||
override val nullability: ConeNullability
|
||||
get() = ConeNullability.UNKNOWN
|
||||
|
||||
override fun toString(): String {
|
||||
return "<ERROR CLASS: $reason>"
|
||||
}
|
||||
@@ -99,3 +119,11 @@ abstract class ConeFunctionType : ConeClassLikeType() {
|
||||
abstract val parameterTypes: List<ConeKotlinType>
|
||||
abstract val returnType: ConeKotlinType
|
||||
}
|
||||
|
||||
class ConeFlexibleType(val lowerBound: ConeKotlinType, val upperBound: ConeKotlinType) : ConeKotlinType() {
|
||||
override val typeArguments: Array<out ConeKotlinTypeProjection>
|
||||
get() = emptyArray()
|
||||
|
||||
override val nullability: ConeNullability
|
||||
get() = lowerBound.nullability.takeIf { it == upperBound.nullability } ?: ConeNullability.UNKNOWN
|
||||
}
|
||||
|
||||
@@ -9,13 +9,17 @@ import org.jetbrains.kotlin.fir.symbols.ConeClassLikeSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeFunctionType
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinTypeProjection
|
||||
import org.jetbrains.kotlin.fir.types.ConeNullability
|
||||
|
||||
class ConeFunctionTypeImpl(
|
||||
override val receiverType: ConeKotlinType?,
|
||||
override val parameterTypes: List<ConeKotlinType>,
|
||||
override val returnType: ConeKotlinType,
|
||||
override val symbol: ConeClassLikeSymbol
|
||||
override val symbol: ConeClassLikeSymbol,
|
||||
isNullable: Boolean
|
||||
) : ConeFunctionType() {
|
||||
override val typeArguments: Array<out ConeKotlinTypeProjection>
|
||||
get() = EMPTY_ARRAY
|
||||
|
||||
override val nullability: ConeNullability = ConeNullability.create(isNullable)
|
||||
}
|
||||
@@ -11,19 +11,30 @@ import org.jetbrains.kotlin.fir.types.*
|
||||
|
||||
open class ConeClassTypeImpl(
|
||||
override val symbol: ConeClassLikeSymbol,
|
||||
override val typeArguments: Array<ConeKotlinTypeProjection>
|
||||
) : ConeClassLikeType()
|
||||
override val typeArguments: Array<ConeKotlinTypeProjection>,
|
||||
isNullable: Boolean
|
||||
) : ConeClassLikeType() {
|
||||
override val nullability: ConeNullability = ConeNullability.create(isNullable)
|
||||
}
|
||||
|
||||
class ConeAbbreviatedTypeImpl(
|
||||
override val abbreviationSymbol: ConeClassLikeSymbol,
|
||||
override val typeArguments: Array<ConeKotlinTypeProjection>,
|
||||
override val directExpansion: ConeClassLikeType
|
||||
override val directExpansion: ConeClassLikeType,
|
||||
isNullable: Boolean
|
||||
) : ConeAbbreviatedType() {
|
||||
override val symbol: ConeClassLikeSymbol
|
||||
get() = abbreviationSymbol
|
||||
|
||||
override val nullability: ConeNullability = ConeNullability.create(isNullable)
|
||||
}
|
||||
|
||||
class ConeTypeParameterTypeImpl(override val symbol: ConeTypeParameterSymbol) : ConeTypeParameterType() {
|
||||
class ConeTypeParameterTypeImpl(
|
||||
override val symbol: ConeTypeParameterSymbol,
|
||||
isNullable: Boolean
|
||||
) : ConeTypeParameterType() {
|
||||
override val typeArguments: Array<out ConeKotlinTypeProjection>
|
||||
get() = EMPTY_ARRAY
|
||||
|
||||
override val nullability: ConeNullability = ConeNullability.create(isNullable)
|
||||
}
|
||||
Reference in New Issue
Block a user