Files
kotlin-fork/compiler/testData/codegen/box/builtinStubMethods/Map.kt
T
Mikhail Glukhikh 672b5ba0d7 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
2024-01-30 19:44:00 +00:00

34 lines
954 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
class MyMap<K, V>: Map<K, V> {
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun containsKey(key: K): Boolean = false
override fun containsValue(value: V): Boolean = false
override fun get(key: K): V? = null
override val keys: Set<K> get() = throw UnsupportedOperationException()
override val values: Collection<V> get() = throw UnsupportedOperationException()
override val entries: Set<Map.Entry<K, V>> get() = throw UnsupportedOperationException()
}
fun expectUoe(block: () -> Unit) {
try {
block()
throw AssertionError()
} catch (e: UnsupportedOperationException) {
}
}
fun box(): String {
val myMap = MyMap<String, Int>()
val map = myMap as java.util.Map<String, Int>
expectUoe { map.put("", 1) }
expectUoe { map.remove("") }
expectUoe { map.putAll(myMap) }
expectUoe { map.clear() }
return "OK"
}