From e5334ed9b84d20c960744d55ea2b4ca0b17fd22d Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Wed, 23 Sep 2015 17:40:48 +0300 Subject: [PATCH] Compare arrays via equals (not Arrays.equals) in data classes --- .../kotlin/codegen/ImplementationBodyCodegen.java | 13 +------------ .../dataClasses/equals/genericarray.kt | 4 +++- .../boxWithStdlib/dataClasses/equals/intarray.kt | 4 +++- .../replaceWith/DeprecatedSymbolUsageFixBase.kt | 2 +- .../replaceWith/ReplaceWithAnnotationAnalyzer.kt | 2 +- .../quickfix/DeprecatedSymbolUsageFixSpecialTest.kt | 2 +- 6 files changed, 10 insertions(+), 17 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index b176bf545fa..7607e00a4bf 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -503,18 +503,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { Type otherPropertyType = genPropertyOnStack(iv, context, propertyDescriptor, 2); StackValue.coerce(otherPropertyType, asmType, iv); - if (asmType.getSort() == Type.ARRAY) { - Type elementType = correctElementType(asmType); - if (elementType.getSort() == Type.OBJECT || elementType.getSort() == Type.ARRAY) { - iv.invokestatic("java/util/Arrays", "equals", "([Ljava/lang/Object;[Ljava/lang/Object;)Z", false); - } - else { - iv.invokestatic("java/util/Arrays", "equals", - "(" + asmType.getDescriptor() + asmType.getDescriptor() + ")Z", false); - } - iv.ifeq(ne); - } - else if (asmType.getSort() == Type.FLOAT) { + if (asmType.getSort() == Type.FLOAT) { iv.invokestatic("java/lang/Float", "compare", "(FF)I", false); iv.ifne(ne); } diff --git a/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/genericarray.kt b/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/genericarray.kt index 1744aa1255d..eaf4b04032e 100644 --- a/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/genericarray.kt +++ b/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/genericarray.kt @@ -1,6 +1,8 @@ data class A(val v: Array) fun box() : String { - if(A(arrayOf(0,1,2)) != A(arrayOf(0,1,2))) return "fail" + val myArray = arrayOf(0, 1, 2) + if(A(myArray) == A(arrayOf(0, 1, 2))) return "fail" + if(A(myArray) != A(myArray)) return "fail 2" return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/intarray.kt b/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/intarray.kt index ea2024b3367..85eb1bec509 100644 --- a/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/intarray.kt +++ b/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/intarray.kt @@ -1,6 +1,8 @@ data class A(val v: IntArray) fun box() : String { - if(A(intArrayOf(0,1,2)) != A(intArrayOf(0,1,2))) return "fail" + val myArray = intArrayOf(0, 1, 2) + if(A(myArray) == A(intArrayOf(0, 1, 2))) return "fail" + if(A(myArray) != A(myArray)) return "fail 2" return "OK" } \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt index 33c5d5b797e..9a78679594f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageFixBase.kt @@ -73,7 +73,7 @@ public abstract class DeprecatedSymbolUsageFixBase( if (descriptor is CallableDescriptor && descriptor.valueParameters.any { it.hasDefaultValue() && OptionalParametersHelper.defaultParameterValue(it, project) == null }) return null - return ReplaceWith(pattern, *imports.toTypedArray()) + return ReplaceWith(pattern, imports) } data class Data( diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/ReplaceWithAnnotationAnalyzer.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/ReplaceWithAnnotationAnalyzer.kt index 772fdddb959..89252c0dee3 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/ReplaceWithAnnotationAnalyzer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/ReplaceWithAnnotationAnalyzer.kt @@ -51,7 +51,7 @@ import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices import org.jetbrains.kotlin.utils.addIfNotNull import java.util.* -data class ReplaceWith(val pattern: String, vararg val imports: String) +data class ReplaceWith(val pattern: String, val imports: List) object ReplaceWithAnnotationAnalyzer { public val PARAMETER_USAGE_KEY: Key = Key("PARAMETER_USAGE") diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixSpecialTest.kt b/idea/tests/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixSpecialTest.kt index 12e9881c49b..f7d2d13cb61 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixSpecialTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/DeprecatedSymbolUsageFixSpecialTest.kt @@ -55,7 +55,7 @@ public class DeprecatedSymbolUsageFixSpecialTest : JetLightCodeInsightFixtureTes val element = getFile().findElementAt(offset) val nameExpression = element!!.parents.firstIsInstance() getProject().executeWriteCommand("") { - DeprecatedSymbolUsageFix(nameExpression, ReplaceWith(pattern)).invoke(getProject(), getEditor(), getFile()) + DeprecatedSymbolUsageFix(nameExpression, ReplaceWith(pattern, emptyList())).invoke(getProject(), getEditor(), getFile()) } myFixture.checkResultByFile("$testPath.after")