[kotlin] Use semanticallyEquals instead of KaType.equals

#KTIJ-29056

GitOrigin-RevId: e480355542dc9ae9228b70f4ab581da3a90c069d
This commit is contained in:
Vladimir Dolzhenko
2024-07-23 12:58:53 +02:00
committed by intellij-monorepo-bot
parent 05278c3668
commit fc832724ee
2 changed files with 9 additions and 6 deletions

View File

@@ -917,14 +917,14 @@
<constraint name="Expression" nameOfExprType="java\.util\.stream\.Stream" exprTypeWithinHierarchy="true" target="true" within="" contains="" />
<constraint name="params" minCount="0" maxCount="2147483647" within="" contains="" />
</searchConfiguration>
<replaceConfiguration name="Call to 'equals()' on KtType" description="Calling `equals` on two types only checks whether the structure of the types is equal, not whether the types are actually equal." suppressId="EqualsOnKtType" text="$lType$ == $rType$" recursive="false" caseInsensitive="true" type="Kotlin" pattern_context="default" reformatAccordingToStyle="false" shortenFQN="false" replacement="$lType$.isEqualTo($rType$)">
<replaceConfiguration name="Call to 'equals()' on KaType" description="Calling `equals` on two types only checks whether the structure of the types is equal, not whether the types are actually equal." suppressId="EqualsOnKaType" text="$lType$ == $rType$" recursive="false" caseInsensitive="true" type="Kotlin" pattern_context="default" reformatAccordingToStyle="false" shortenFQN="false" replacement="$lType$.semanticallyEquals($rType$)">
<constraint name="__context__" within="" contains="" />
<constraint name="lType" nameOfExprType="org\.jetbrains\.kotlin\.analysis\.api\.types\.KtType" within="" contains="" />
<constraint name="lType" nameOfExprType="org\.jetbrains\.kotlin\.analysis\.api\.types\.KaType" within="" contains="" />
<constraint name="rType" within="" contains="" />
</replaceConfiguration>
<replaceConfiguration name="Call to 'equals()' on KtType" text="$lType$ != $rType$" recursive="false" caseInsensitive="true" type="Kotlin" pattern_context="default" reformatAccordingToStyle="false" shortenFQN="false" replacement="!$lType$.isEqualTo($rType$)">
<replaceConfiguration name="Call to 'equals()' on KaType" text="$lType$ != $rType$" recursive="false" caseInsensitive="true" type="Kotlin" pattern_context="default" reformatAccordingToStyle="false" shortenFQN="false" replacement="!$lType$.semanticallyEquals($rType$)">
<constraint name="__context__" within="" contains="" />
<constraint name="lType" nameOfExprType="org\.jetbrains\.kotlin\.analysis\.api\.types\.KtType" within="" contains="" />
<constraint name="lType" nameOfExprType="org\.jetbrains\.kotlin\.analysis\.api\.types\.KaType" within="" contains="" />
<constraint name="rType" within="" contains="" />
</replaceConfiguration>
<replaceConfiguration name="can be simplified to ReadAction.compute()" uuid="44cf5267-e665-3ff5-9d2f-0de5c6983156" text="$application$.runReadAction(new $Computable$() {&#10; public $SearchScope$ compute() {&#10; return $e$;&#10; }&#10;})" recursive="false" caseInsensitive="true" type="JAVA" reformatAccordingToStyle="true" shortenFQN="true" replacement="com.intellij.openapi.application.ReadAction.compute(()-&gt;$e$)">

View File

@@ -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