From e06ae01c0cb1a8de7cda55b615014ba28a46b3d4 Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Thu, 8 Oct 2020 16:20:56 +0300 Subject: [PATCH] Restore nullability after type refinement along with annotations See the issue for details ^KT-42546 Fixed --- .../org/jetbrains/kotlin/types/KotlinTypeRefinerImpl.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/KotlinTypeRefinerImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/KotlinTypeRefinerImpl.kt index 0b34268da17..fe63784aae2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/KotlinTypeRefinerImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/KotlinTypeRefinerImpl.kt @@ -67,7 +67,8 @@ class KotlinTypeRefinerImpl( val cached = refinedTypeCache.computeIfAbsent(type.constructor) { type.constructor.declarationDescriptor!!.defaultType.refine(this) } - cached.replace(type.arguments) + + cached.restoreAdditionalTypeInformation(type) } else -> type.refine(this) } @@ -146,3 +147,7 @@ private val TypeConstructor.allDependentTypeConstructors: Collection()?.isExpect == true + +private fun KotlinType.restoreAdditionalTypeInformation(prototype: KotlinType): KotlinType { + return TypeUtils.makeNullableAsSpecified(this, prototype.isMarkedNullable).replace(prototype.arguments) +}