From 6cb6abee982213c8bc1e6132399a40d30deef495 Mon Sep 17 00:00:00 2001 From: pyos Date: Mon, 26 Jul 2021 23:05:36 +0200 Subject: [PATCH] FE: do not create multiple layers of enhancements for warnings --- .../org/jetbrains/kotlin/types/TypeWithEnhancement.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeWithEnhancement.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeWithEnhancement.kt index 2afbbecfd91..2140ff5dcf0 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeWithEnhancement.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeWithEnhancement.kt @@ -51,6 +51,9 @@ class SimpleTypeWithEnhancement( kotlinTypeRefiner.refineType(delegate) as SimpleType, kotlinTypeRefiner.refineType(enhancement) ) + + override fun toString(): String = + "[@EnhancedForWarnings($enhancement)] $origin" } class FlexibleTypeWithEnhancement( @@ -81,6 +84,9 @@ class FlexibleTypeWithEnhancement( kotlinTypeRefiner.refineType(origin) as FlexibleType, kotlinTypeRefiner.refineType(enhancement) ) + + override fun toString(): String = + "[@EnhancedForWarnings($enhancement)] $origin" } fun KotlinType.getEnhancement(): KotlinType? = when (this) { @@ -150,10 +156,12 @@ fun UnwrappedType.inheritEnhancement(origin: KotlinType, transform: (KotlinType) fun UnwrappedType.inheritEnhancement(origin: KotlinType): UnwrappedType = wrapEnhancement(origin.getEnhancement()) fun UnwrappedType.wrapEnhancement(enhancement: KotlinType?): UnwrappedType { + if (this is TypeWithEnhancement) { + return origin.wrapEnhancement(enhancement) + } if (enhancement == null) { return this } - return when (this) { is SimpleType -> SimpleTypeWithEnhancement(this, enhancement) is FlexibleType -> FlexibleTypeWithEnhancement(this, enhancement)