[FIR] Fix false negative ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS
... in presence of typealiases. #KT-61921
This commit is contained in:
committed by
Space Team
parent
9475bc250c
commit
9949de36c9
+7
@@ -1,12 +1,19 @@
|
||||
FILE: ArrayEqualityCanBeReplacedWithEquals.kt
|
||||
public final typealias A<T> = R|kotlin/Array<T>|
|
||||
public final fun foo(p: R|kotlin/Int|): R|kotlin/Unit| {
|
||||
lval a: R|kotlin/Array<kotlin/Int>| = R|kotlin/arrayOf|<R|kotlin/Int|>(vararg(Int(1), Int(2), Int(3)))
|
||||
lval b: R|kotlin/Array<kotlin/Int>| = R|kotlin/arrayOf|<R|kotlin/Int|>(vararg(Int(3), Int(2), Int(1)))
|
||||
lval c: R|A<kotlin/Int>| = R|kotlin/arrayOf|<R|kotlin/Int|>(vararg(Int(3), Int(2), Int(1)))
|
||||
when () {
|
||||
==(R|<local>/a|, R|<local>/b|) -> {
|
||||
}
|
||||
}
|
||||
|
||||
when () {
|
||||
==(R|<local>/a|, R|<local>/c|) -> {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public final fun testsFromIdea(): R|kotlin/Unit| {
|
||||
lval a: R|kotlin/Array<kotlin/String>| = R|kotlin/arrayOf|<R|kotlin/String|>(vararg(String(a)))
|
||||
|
||||
+4
@@ -1,10 +1,14 @@
|
||||
// WITH_STDLIB
|
||||
|
||||
typealias A<T> = Array<T>
|
||||
|
||||
fun foo(p: Int) {
|
||||
val a = arrayOf(1, 2, 3)
|
||||
val b = arrayOf(3, 2, 1)
|
||||
val c : A<Int> = arrayOf(3, 2, 1)
|
||||
|
||||
if (a <!ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS!>==<!> b) { }
|
||||
if (a <!ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS!>==<!> c) { }
|
||||
}
|
||||
|
||||
fun testsFromIdea() {
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.fir.expressions.FirEqualityOperatorCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirOperation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.expressions.arguments
|
||||
import org.jetbrains.kotlin.fir.types.classId
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.fullyExpandedClassId
|
||||
import org.jetbrains.kotlin.fir.types.resolvedType
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
|
||||
@@ -26,8 +26,8 @@ object ArrayEqualityCanBeReplacedWithEquals : FirBasicExpressionChecker() {
|
||||
val left = arguments.getOrNull(0) ?: return
|
||||
val right = arguments.getOrNull(1) ?: return
|
||||
|
||||
if (left.resolvedType.classId != StandardClassIds.Array) return
|
||||
if (right.resolvedType.classId != StandardClassIds.Array) return
|
||||
if (left.resolvedType.fullyExpandedClassId(context.session) != StandardClassIds.Array) return
|
||||
if (right.resolvedType.fullyExpandedClassId(context.session) != StandardClassIds.Array) return
|
||||
|
||||
reporter.reportOn(expression.source, ARRAY_EQUALITY_OPERATOR_CAN_BE_REPLACED_WITH_EQUALS, context)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user