From af79265f42a376c7c05b5de94aa658bd47cea6c6 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Fri, 26 Feb 2021 18:09:11 +0300 Subject: [PATCH] [FIR] Fix creating overrides for functions with name same as renamed in JVM builtins --- .../java/scopes/JavaClassUseSiteMemberScope.kt | 8 +++----- .../extendJavaCollections/arrayList.kt | 1 - .../collections/removeAtBridgeClashWithJava.kt | 1 - .../bytecodeText/builtinFunctions/removeAt.kt | 2 -- .../ir/irText/firProblems/MultiList.fir.txt | 16 ++++++++-------- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt index 291957cb2a4..1a0d0b2652c 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassUseSiteMemberScope.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.SpecialGenericSignatures import org.jetbrains.kotlin.load.java.SpecialGenericSignatures.Companion.ERASED_COLLECTION_PARAMETER_NAMES import org.jetbrains.kotlin.load.java.SpecialGenericSignatures.Companion.sameAsBuiltinMethodWithErasedValueParameters +import org.jetbrains.kotlin.load.java.SpecialGenericSignatures.Companion.sameAsRenamedInJvmBuiltin import org.jetbrains.kotlin.load.java.getPropertyNamesCandidatesByAccessorName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.AbstractTypeChecker @@ -191,7 +192,7 @@ class JavaClassUseSiteMemberScope( val renamedSpecialBuiltInNames = SpecialGenericSignatures.getBuiltinFunctionNamesByJvmName(name) if (potentialPropertyNames.isEmpty() && renamedSpecialBuiltInNames.isEmpty() && - !name.sameAsBuiltinMethodWithErasedValueParameters + !name.sameAsBuiltinMethodWithErasedValueParameters && !name.sameAsRenamedInJvmBuiltin ) { return super.processFunctionsByName(name, processor) } @@ -387,10 +388,7 @@ class JavaClassUseSiteMemberScope( superTypesScope.processOverriddenFunctions(this) { if (!it.isFromBuiltInClass(session)) return@processOverriddenFunctions ProcessorAction.NEXT - if (SpecialGenericSignatures.SIGNATURE_TO_JVM_REPRESENTATION_NAME.containsKey( - it.fir.computeJvmSignature() - ) - ) { + if (SpecialGenericSignatures.SIGNATURE_TO_JVM_REPRESENTATION_NAME.containsKey(it.fir.computeJvmSignature())) { result = it return@processOverriddenFunctions ProcessorAction.STOP } diff --git a/compiler/testData/codegen/box/builtinStubMethods/extendJavaCollections/arrayList.kt b/compiler/testData/codegen/box/builtinStubMethods/extendJavaCollections/arrayList.kt index d28b819ef07..2b9587cfbd7 100644 --- a/compiler/testData/codegen/box/builtinStubMethods/extendJavaCollections/arrayList.kt +++ b/compiler/testData/codegen/box/builtinStubMethods/extendJavaCollections/arrayList.kt @@ -1,6 +1,5 @@ // DONT_TARGET_EXACT_BACKEND: WASM // WASM_MUTE_REASON: STDLIB_COLLECTIONS -// IGNORE_BACKEND_FIR: JVM_IR // KJS_WITH_FULL_RUNTIME // KT-6042 java.lang.UnsupportedOperationException with ArrayList // IGNORE_BACKEND: NATIVE diff --git a/compiler/testData/codegen/box/collections/removeAtBridgeClashWithJava.kt b/compiler/testData/codegen/box/collections/removeAtBridgeClashWithJava.kt index 203cdd5eb3f..a5123ef9a7d 100644 --- a/compiler/testData/codegen/box/collections/removeAtBridgeClashWithJava.kt +++ b/compiler/testData/codegen/box/collections/removeAtBridgeClashWithJava.kt @@ -1,5 +1,4 @@ // TARGET_BACKEND: JVM -// IGNORE_BACKEND_FIR: JVM_IR // WITH_RUNTIME // FILE: removeAtBridgeClashWithJava.kt diff --git a/compiler/testData/codegen/bytecodeText/builtinFunctions/removeAt.kt b/compiler/testData/codegen/bytecodeText/builtinFunctions/removeAt.kt index c36688ce7a5..46a7a958730 100644 --- a/compiler/testData/codegen/bytecodeText/builtinFunctions/removeAt.kt +++ b/compiler/testData/codegen/bytecodeText/builtinFunctions/removeAt.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR - abstract class A1 : MutableList { override fun remove(x: T): Boolean = true override fun removeAt(index: Int): T = null!! diff --git a/compiler/testData/ir/irText/firProblems/MultiList.fir.txt b/compiler/testData/ir/irText/firProblems/MultiList.fir.txt index 2f0b323d21b..20fd8d991f2 100644 --- a/compiler/testData/ir/irText/firProblems/MultiList.fir.txt +++ b/compiler/testData/ir/irText/firProblems/MultiList.fir.txt @@ -392,11 +392,11 @@ FILE fqName: fileName:/MultiList.kt public open fun sort (p0: java.util.Comparator?): kotlin.Unit declared in java.util.ArrayList $this: VALUE_PARAMETER name: type:java.util.ArrayList VALUE_PARAMETER name:p0 index:0 type:java.util.Comparator.Some.SomeList>?>? - FUN FAKE_OVERRIDE name:removeAt visibility:public modality:ABSTRACT <> ($this:kotlin.collections.MutableList, index:kotlin.Int) returnType:.Some.SomeList>? [fake_override] + FUN FAKE_OVERRIDE name:removeAt visibility:public modality:OPEN <> ($this:java.util.ArrayList, p0:kotlin.Int) returnType:.Some.SomeList>? [fake_override] overridden: - public abstract fun removeAt (index: kotlin.Int): @[FlexibleNullability] E of java.util.ArrayList? [fake_override] declared in java.util.ArrayList - $this: VALUE_PARAMETER name: type:kotlin.collections.MutableList - VALUE_PARAMETER name:index index:0 type:kotlin.Int + public open fun removeAt (p0: kotlin.Int): E of java.util.ArrayList? declared in java.util.ArrayList + $this: VALUE_PARAMETER name: type:java.util.ArrayList + VALUE_PARAMETER name:p0 index:0 type:kotlin.Int CLASS CLASS name:FinalList modality:FINAL visibility:public superTypes:[.SomeList] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.FinalList CONSTRUCTOR visibility:public <> () returnType:.FinalList [primary] @@ -584,8 +584,8 @@ FILE fqName: fileName:/MultiList.kt public open fun sort (p0: java.util.Comparator.Some.SomeList>?>?): kotlin.Unit [fake_override] declared in .SomeList $this: VALUE_PARAMETER name: type:java.util.ArrayList VALUE_PARAMETER name:p0 index:0 type:java.util.Comparator.Some?>? - FUN FAKE_OVERRIDE name:removeAt visibility:public modality:ABSTRACT <> ($this:kotlin.collections.MutableList, index:kotlin.Int) returnType:.Some? [fake_override] + FUN FAKE_OVERRIDE name:removeAt visibility:public modality:OPEN <> ($this:java.util.ArrayList, p0:kotlin.Int) returnType:.Some? [fake_override] overridden: - public abstract fun removeAt (index: kotlin.Int): .Some.SomeList>? [fake_override] declared in .SomeList - $this: VALUE_PARAMETER name: type:kotlin.collections.MutableList - VALUE_PARAMETER name:index index:0 type:kotlin.Int + public open fun removeAt (p0: kotlin.Int): .Some.SomeList>? [fake_override] declared in .SomeList + $this: VALUE_PARAMETER name: type:java.util.ArrayList + VALUE_PARAMETER name:p0 index:0 type:kotlin.Int