K2/Java: implement platform-dependent function filtering in JvmMappedScope

We drop Kotlin function 'remove' or 'getOrDefault' from JvmMappedScope,
if it has platform-dependent annotation, and the bound Java class scope
does not contain a function with the same signature.

#KT-57268 Fixed
This commit is contained in:
Mikhail Glukhikh
2024-01-24 16:50:47 +01:00
committed by Space Team
parent 7d584e0eb4
commit 672b5ba0d7
87 changed files with 352 additions and 373 deletions
@@ -1,6 +1,3 @@
// WITH_SIGNATURES
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
abstract class ByteShortMap : Map<Byte, Short>
@@ -1,6 +1,3 @@
// WITH_SIGNATURES
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
abstract class GenericMap<K, V> : Map<K, V>
@@ -1,6 +1,3 @@
// WITH_SIGNATURES
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
abstract class GenericStringMap<K> : Map<K, String>
@@ -1,6 +1,3 @@
// WITH_SIGNATURES
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
abstract class NumberStringMap : Map<Number, String>
@@ -1,8 +1,5 @@
// WITH_SIGNATURES
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
abstract class GenericMap<K, V> : Map<K, V>
abstract class NumberStringMap : GenericMap<Number, String>()
@@ -1,6 +1,3 @@
// WITH_SIGNATURES
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
abstract class StringGenericMap<V> : Map<String, V>
@@ -0,0 +1,103 @@
MODULE main
CLASS DGenericCollection.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
CLASS DGenericSet.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
CLASS DGenericList.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
CLASS DGenericMap.class
CLASS METADATA
K1
---
K2
entries
K1
getEntries()Ljava/util/Set;
K2
---
K1
getKeys()Ljava/util/Set;
K2
---
K1
getSize()I
K2
---
K1
getValues()Ljava/util/Collection;
K2
---
K1
---
K2
keys
K1
---
K2
size
K1
---
K2
values
CLASS DGenericMapEntry.class
CLASS METADATA
K1
getKey()Ljava/lang/Object;
K2
---
K1
getValue()Ljava/lang/Object;
K2
---
K1
---
K2
key
K1
---
K2
value
CLASS DGenericCollectionBySet.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
CLASS DGenericCollectionByList.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
@@ -1,5 +1,4 @@
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
// JVM_ABI_K1_K2_DIFF: KT-65323
class DGenericIterator<T>(d: Iterator<T>) : Iterator<T> by d
@@ -0,0 +1,103 @@
MODULE main
CLASS DStringCollection.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
CLASS DStringSet.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
CLASS DStringList.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
CLASS DStringMap.class
CLASS METADATA
K1
---
K2
entries
K1
getEntries()Ljava/util/Set;
K2
---
K1
getKeys()Ljava/util/Set;
K2
---
K1
getSize()I
K2
---
K1
getValues()Ljava/util/Collection;
K2
---
K1
---
K2
keys
K1
---
K2
size
K1
---
K2
values
CLASS DStringMapEntry.class
CLASS METADATA
K1
getKey()Ljava/lang/String;
K2
---
K1
getValue()Ljava/lang/Number;
K2
---
K1
---
K2
key
K1
---
K2
value
CLASS DStringCollectionBySet.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
CLASS DStringCollectionByList.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
@@ -1,5 +1,4 @@
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
// JVM_ABI_K1_K2_DIFF: KT-65323
class DStringIterator(d: Iterator<String>) : Iterator<String> by d
@@ -0,0 +1,103 @@
MODULE main
CLASS DIntCollection.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
CLASS DIntSet.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
CLASS DIntList.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
CLASS DIntMap.class
CLASS METADATA
K1
---
K2
entries
K1
getEntries()Ljava/util/Set;
K2
---
K1
getKeys()Ljava/util/Set;
K2
---
K1
getSize()I
K2
---
K1
getValues()Ljava/util/Collection;
K2
---
K1
---
K2
keys
K1
---
K2
size
K1
---
K2
values
CLASS DIntMapEntry.class
CLASS METADATA
K1
getKey()Ljava/lang/Integer;
K2
---
K1
getValue()Ljava/lang/Double;
K2
---
K1
---
K2
key
K1
---
K2
value
CLASS DIntCollectionBySet.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
CLASS DIntCollectionByList.class
CLASS METADATA
K1
getSize()I
K2
---
K1
---
K2
size
@@ -1,5 +1,4 @@
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
// JVM_ABI_K1_K2_DIFF: KT-65323
class DIntIterator(d: Iterator<Int>) : Iterator<Int> by d
@@ -1,9 +1,7 @@
// WITH_STDLIB
// IGNORE_BACKEND_K2: JVM_IR
// FIR status:
// 1) KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
// 2) KT-57300 K2: subclass of MutableCollection with primitive element type has methods with boxed type
// FIR status: KT-57300 K2: subclass of MutableCollection with primitive element type has methods with boxed type
// (`containsValue(Ljava/lang/Double;)Z` instead of `containsValue(D)Z`)
abstract class AMapSD : AbstractMap<String, Double>()
@@ -0,0 +1,9 @@
MODULE main
CLASS MyMap.class
CLASS METADATA
PROPERTY getValues()Ljava/util/ArrayList;
Property: class.metadata.property.returnType
K1
java/util/ArrayList<T#1> /* = kotlin/collections/ArrayList^<T#1> */
K2
java/util/ArrayList<T#1>
@@ -1,9 +1,8 @@
// JVM_ABI_K1_K2_DIFF: KT-63864
// Ensure the proper collection stubs are added, in
// particular *not* when specialized implementations are provided.
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
class MyMap<K, V> : Map<K, V> {
class MySet<E> : Set<E> {
@@ -1,8 +1,5 @@
// See KT-42033
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
interface ObservableMap<K, V> : Map<K, V>
abstract class ObservableMutableMap<K, V> : ObservableMap<K, V> {
@@ -1,9 +1,5 @@
// IGNORE_ANNOTATIONS
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
// (in this case, it's `getOrDefault-impl` because of inline class mangling, and then `remove` is unmangled for some reason)
inline class InlineMap<K, V>(private val map: Map<K, V>) : Map<K, V> {
override val entries: Set<Map.Entry<K, V>> get() = map.entries
override val keys: Set<K> get() = map.keys
@@ -1,9 +1,5 @@
// IGNORE_ANNOTATIONS
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
// (in this case, it's `remove-impl`/`getOrDefault-impl` because of inline class mangling)
inline class InlineMutableMap<K, V>(private val mmap: MutableMap<K, V>) : MutableMap<K, V> {
override val size: Int get() = mmap.size
override fun containsKey(key: K): Boolean = mmap.containsKey(key)
@@ -1,9 +1,5 @@
// IGNORE_ANNOTATIONS
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
// (in this case, it's `getOrDefault-h8vw2VU` because of inline class mangling, and then `remove` is unmangled for some reason)
inline class IK(val x: Int)
inline class IV(val x: Double)
@@ -1,9 +1,5 @@
// IGNORE_ANNOTATIONS
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
// (in this case, it's `remove-YEowaJk`/`getOrDefault-h8vw2VU` because of inline class mangling)
inline class IK(val x: Int)
inline class IV(val x: Double)
@@ -1,8 +1,5 @@
// WITH_STDLIB
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
open class A : HashMap<String, String>()
class B : A()
@@ -1,8 +1,5 @@
// WITH_SIGNATURES
// IGNORE_BACKEND_K2: JVM_IR
// FIR status: KT-57268 K2: extra methods `remove` and/or `getOrDefault` are generated for Map subclasses with JDK 1.6 in dependencies
interface MapN<K : Number, V> : Map<K, V>
abstract class MapImpl<A, B> : Map<A, B> {