From 59c4b9ad2fcbdfe42ba39f194ee43010cbfe0ee1 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Wed, 25 Apr 2018 12:07:29 +0300 Subject: [PATCH] [NI] Make it possible to use nullable non-fixed type --- .../model/NewConstraintSystemImpl.kt | 2 +- .../jetbrains/kotlin/types/NonFixedType.kt | 27 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt index dbf27d6ad46..0a1e28d3e96 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt @@ -275,7 +275,7 @@ class NewConstraintSystemImpl( override fun bindingStubsForPostponedVariables(): Map { 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 { diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/NonFixedType.kt b/core/descriptors/src/org/jetbrains/kotlin/types/NonFixedType.kt index d58e2421996..931245e01a1 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/NonFixedType.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/NonFixedType.kt @@ -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 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"