From ecde5414dc984e7a418166505e93bbf0b7c37361 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Tue, 11 May 2021 19:25:23 +0300 Subject: [PATCH] Reuse error type constructor for stub types --- .../org/jetbrains/kotlin/types/StubTypes.kt | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/StubTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/StubTypes.kt index 2f88e708555..6bf465bbbd0 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/StubTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/StubTypes.kt @@ -13,9 +13,10 @@ import org.jetbrains.kotlin.types.refinement.TypeRefinement class StubTypeForBuilderInference( originalTypeVariable: TypeConstructor, isMarkedNullable: Boolean, + override val constructor: TypeConstructor = createConstructor(originalTypeVariable) ) : AbstractStubType(originalTypeVariable, isMarkedNullable), StubTypeMarker { override fun materialize(newNullability: Boolean): AbstractStubType = - StubTypeForBuilderInference(originalTypeVariable, newNullability) + StubTypeForBuilderInference(originalTypeVariable, newNullability, constructor) override val memberScope = originalTypeVariable.builtIns.anyType.memberScope @@ -25,10 +26,13 @@ class StubTypeForBuilderInference( } } -class StubTypeForTypeVariablesInSubtyping(originalTypeVariable: TypeConstructor, isMarkedNullable: Boolean) : - AbstractStubType(originalTypeVariable, isMarkedNullable), StubTypeMarker { +class StubTypeForTypeVariablesInSubtyping( + originalTypeVariable: TypeConstructor, + isMarkedNullable: Boolean, + override val constructor: TypeConstructor = createConstructor(originalTypeVariable) +) : AbstractStubType(originalTypeVariable, isMarkedNullable), StubTypeMarker { override fun materialize(newNullability: Boolean): AbstractStubType = - StubTypeForTypeVariablesInSubtyping(originalTypeVariable, newNullability) + StubTypeForTypeVariablesInSubtyping(originalTypeVariable, newNullability, constructor) override fun toString(): String { return "Stub (subtyping): $originalTypeVariable${if (isMarkedNullable) "?" else ""}" @@ -36,10 +40,13 @@ class StubTypeForTypeVariablesInSubtyping(originalTypeVariable: TypeConstructor, } // This type is used as a replacement of type variables for provideDelegate resolve -class StubTypeForProvideDelegateReceiver(originalTypeVariable: TypeConstructor, isMarkedNullable: Boolean) : - AbstractStubType(originalTypeVariable, isMarkedNullable) { +class StubTypeForProvideDelegateReceiver( + originalTypeVariable: TypeConstructor, + isMarkedNullable: Boolean, + override val constructor: TypeConstructor = createConstructor(originalTypeVariable) +) : AbstractStubType(originalTypeVariable, isMarkedNullable) { override fun materialize(newNullability: Boolean): StubTypeForProvideDelegateReceiver = - StubTypeForProvideDelegateReceiver(originalTypeVariable, newNullability) + StubTypeForProvideDelegateReceiver(originalTypeVariable, newNullability, constructor) override fun toString(): String { return "Stub (delegation): $originalTypeVariable${if (isMarkedNullable) "?" else ""}" @@ -48,7 +55,6 @@ class StubTypeForProvideDelegateReceiver(originalTypeVariable: TypeConstructor, abstract class AbstractStubType(val originalTypeVariable: TypeConstructor, override val isMarkedNullable: Boolean) : SimpleType() { override val memberScope = ErrorUtils.createErrorScope("Scope for stub type: $originalTypeVariable") - override val constructor = ErrorUtils.createErrorTypeConstructor("Constructor for stub type: $originalTypeVariable") override val arguments: List get() = emptyList() @@ -66,4 +72,9 @@ abstract class AbstractStubType(val originalTypeVariable: TypeConstructor, overr override fun refine(kotlinTypeRefiner: KotlinTypeRefiner) = this abstract fun materialize(newNullability: Boolean): AbstractStubType + + companion object { + fun createConstructor(originalTypeVariable: TypeConstructor) = + ErrorUtils.createErrorTypeConstructor("Constructor for stub type: $originalTypeVariable") + } } \ No newline at end of file