[NI] Make it possible to use nullable non-fixed type

This commit is contained in:
Mikhail Zarechenskiy
2018-04-25 12:07:29 +03:00
parent 9209222112
commit 59c4b9ad2f
2 changed files with 18 additions and 11 deletions
@@ -275,7 +275,7 @@ class NewConstraintSystemImpl(
override fun bindingStubsForPostponedVariables(): Map<NewTypeVariable, NonFixedType> {
checkState(State.BUILDING, State.COMPLETION)
return storage.postponedTypeVariables.associate { it to NonFixedType(it.freshTypeConstructor) }
return storage.postponedTypeVariables.associate { it to NonFixedType(it.freshTypeConstructor, it.defaultType.isMarkedNullable) }
}
override fun copyCurrentStorage(): ConstraintStorage {
@@ -8,25 +8,32 @@ package org.jetbrains.kotlin.types
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.scopes.MemberScope
class NonFixedType(val originalTypeVariable: TypeConstructor) : SimpleType() {
// This type is used as a stub for postponed type variables, which are important for coroutine inference
class NonFixedType(
private val originalTypeVariable: TypeConstructor,
override val isMarkedNullable: Boolean,
override val constructor: TypeConstructor =
ErrorUtils.createErrorTypeConstructor("Constructor for non fixed type: $originalTypeVariable")
ErrorUtils.createErrorTypeConstructor("Constructor for non fixed type: $originalTypeVariable"),
override val memberScope: MemberScope =
ErrorUtils.createErrorScope("Scope for non fixed type: $originalTypeVariable")
) : SimpleType() {
override val arguments: List<TypeProjection>
get() = emptyList()
override val isMarkedNullable: Boolean
get() = false
override val memberScope: MemberScope =
ErrorUtils.createErrorScope("Scope for non fixed type: $originalTypeVariable")
override val annotations: Annotations
get() = Annotations.EMPTY
override fun replaceAnnotations(newAnnotations: Annotations): SimpleType = this
override fun replaceAnnotations(newAnnotations: Annotations): SimpleType {
error("Shouldn't be called on non-fixed type")
}
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType = this
override fun makeNullableAsSpecified(newNullability: Boolean): SimpleType {
return if (newNullability == isMarkedNullable)
this
else
NonFixedType(originalTypeVariable, newNullability, constructor, memberScope)
}
override fun toString(): String {
return "NonFixed: $originalTypeVariable"