[FIR] Add nullability to ILT. #KT-37639 Fixed

This commit is contained in:
Dmitriy Novozhilov
2020-03-20 15:32:33 +03:00
parent 006e1f6528
commit 6ce8d661ad
11 changed files with 89 additions and 23 deletions
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.types.model.SimpleTypeMarker
class ConeIntegerLiteralTypeImpl : ConeIntegerLiteralType {
override val possibleTypes: Collection<ConeClassLikeType>
constructor(value: Long) : super(value) {
constructor(value: Long, nullability: ConeNullability = ConeNullability.NOT_NULL) : super(value, nullability) {
possibleTypes = mutableListOf()
fun checkBoundsAndAddPossibleType(classId: ClassId, range: LongRange) {
@@ -34,7 +34,11 @@ class ConeIntegerLiteralTypeImpl : ConeIntegerLiteralType {
// TODO: add support of unsigned types
}
private constructor(value: Long, possibleTypes: Collection<ConeClassLikeType>) : super(value) {
private constructor(
value: Long,
possibleTypes: Collection<ConeClassLikeType>,
nullability: ConeNullability = ConeNullability.NOT_NULL
) : super(value, nullability) {
this.possibleTypes = possibleTypes
}
@@ -46,10 +50,11 @@ class ConeIntegerLiteralTypeImpl : ConeIntegerLiteralType {
}
override fun getApproximatedType(expectedType: ConeKotlinType?): ConeClassLikeType {
return when (expectedType) {
val approximatedType = when (expectedType) {
null, !in possibleTypes -> possibleTypes.first()
else -> expectedType as ConeClassLikeType
}
return approximatedType.withNullability(nullability)
}
companion object {
@@ -121,4 +126,14 @@ fun ConeKotlinType.approximateIntegerLiteralType(expectedType: ConeKotlinType? =
(this as? ConeIntegerLiteralType)?.getApproximatedType(expectedType) ?: this
fun ConeKotlinType.approximateIntegerLiteralTypeOrNull(expectedType: ConeKotlinType? = null): ConeKotlinType? =
(this as? ConeIntegerLiteralType)?.getApproximatedType(expectedType)
(this as? ConeIntegerLiteralType)?.getApproximatedType(expectedType)
private fun ConeClassLikeType.withNullability(nullability: ConeNullability): ConeClassLikeType {
if (nullability == this.nullability) return this
return when (this) {
is ConeClassErrorType -> this
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable)
else -> error("sealed")
}
}