From fc832724ee3f76d9f8a3d4ce3b04060eb4f0a927 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Tue, 23 Jul 2024 12:58:53 +0200 Subject: [PATCH] [kotlin] Use semanticallyEquals instead of KaType.equals #KTIJ-29056 GitOrigin-RevId: e480355542dc9ae9228b70f4ab581da3a90c069d --- .idea/inspectionProfiles/idea_default.xml | 8 ++++---- .../codeinsight/intentions/RemoveExplicitTypeIntention.kt | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.idea/inspectionProfiles/idea_default.xml b/.idea/inspectionProfiles/idea_default.xml index fe1146f66f09..578bc38430d7 100644 --- a/.idea/inspectionProfiles/idea_default.xml +++ b/.idea/inspectionProfiles/idea_default.xml @@ -917,14 +917,14 @@ - + - + - + - + diff --git a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/RemoveExplicitTypeIntention.kt b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/RemoveExplicitTypeIntention.kt index 1235abcf87c5..8c76c12a34e8 100644 --- a/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/RemoveExplicitTypeIntention.kt +++ b/plugins/kotlin/code-insight/intentions-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/intentions/RemoveExplicitTypeIntention.kt @@ -137,11 +137,14 @@ internal class RemoveExplicitTypeIntention : val type = typeReference.type val thenType = initializer.then?.expressionType val elseType = initializer.`else`?.expressionType - type == thenType && type == elseType + thenType != null && elseType != null && type.semanticallyEquals(thenType) && type.semanticallyEquals(elseType) } is KtWhenExpression -> { val type = typeReference.type - initializer.entries.all { it.expression?.expressionType == type } + initializer.entries.all { + val expressionType = it.expression?.expressionType ?: return@all false + expressionType.semanticallyEquals(type) + } } // consider types of expressions that the compiler views as constants, e.g. `1 + 2`, as independent