[NI] Preserve nullability of resulting type from CST if it's possible
Consider common supertype of `S` and `Nothing`, where `S` has nullable upper bound or it's flexible. Before the fix, result was `S?`, which is correct but too conservative. Now, we'll preserve nullability of resulting type if it's already nullable. This happened because we were failing to find path of not-nullable types from `Nothing` to `S`, which should obviously exists by semantics of Nothing
This commit is contained in:
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.types.checker.TypeCheckerContext.SeveralSupertypesWi
|
||||
import org.jetbrains.kotlin.types.checker.TypeCheckerContext.SupertypesPolicy
|
||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||
import org.jetbrains.kotlin.types.typeUtil.isAnyOrNullableAny
|
||||
import org.jetbrains.kotlin.types.typeUtil.isNothing
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
@@ -452,7 +453,7 @@ object NullabilityChecker {
|
||||
}
|
||||
|
||||
private fun TypeCheckerContext.hasPathByNotMarkedNullableNodes(start: SimpleType, end: TypeConstructor) =
|
||||
anySupertype(start, { !it.isMarkedNullable && it.constructor == end }) {
|
||||
anySupertype(start, { it.isNothing() || (!it.isMarkedNullable && it.constructor == end) }) {
|
||||
if (it.isMarkedNullable) SupertypesPolicy.None else SupertypesPolicy.LowerIfFlexible
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user