Files
kotlin-fork/compiler/testData/codegen/box/builtinStubMethods/mapRemove/readOnlyMap.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

49 lines
1.3 KiB
Kotlin
Vendored

// TODO: FirModuleDescriptor provides default builtins which filters out platform-specific functions (and defaults are considered platform-specific)
// SKIP_JDK6
// TARGET_BACKEND: JVM
// FULL_JDK
// WITH_STDLIB
// FILE: A.java
public class A {
public static void foo(java.util.Map<String, String> x) {
x.remove("abc", "cde");
}
}
// FILE: main.kt
class ReadOnlyMap<K, V>(val x: K, val y: V) : Map<K, V> {
override val entries: Set<Map.Entry<K, V>>
get() = throw UnsupportedOperationException()
override val keys: Set<K>
get() = throw UnsupportedOperationException()
override val size: Int
get() = throw UnsupportedOperationException()
override val values: Collection<V>
get() = throw UnsupportedOperationException()
override fun containsKey(key: K) = key == x
override fun containsValue(value: V) = value == y
override fun get(key: K): V? = if (key == x) y else null
override fun isEmpty() = false
}
fun box(): String {
try {
A.foo(ReadOnlyMap("abc", "cde"))
return "fail 1"
} catch (e: UnsupportedOperationException) { }
try {
// Default Map 'remove' implenetation actually does remove iff entry exists
A.foo(ReadOnlyMap("abc", "123"))
return "fail 2"
} catch (e: UnsupportedOperationException) { }
return "OK"
}