Files
kotlin-fork/compiler/testData/codegen/box/builtinStubMethods/delegationToArrayList.kt
T
Jiaxiang Chen afcbd76c9e Implement stub methods generation for Kotlin Immutable Collection classes.
This change is to fill the gap between Kotlin Collection
classes(immutable) and Java Collection classes(mutable), to avoid
calling an unsupported operation like remove() on an immutable class in
jvm.
2019-05-21 17:20:20 +03:00

50 lines
1.1 KiB
Kotlin
Vendored

// TARGET_BACKEND: JVM
import java.util.ArrayList
class A<E> : List<E> by ArrayList<E>()
class B : List<String> by A<String>()
fun expectUoe(block: () -> Any) {
try {
block()
throw AssertionError()
} catch (e: UnsupportedOperationException) {
}
}
fun box(): String {
val a = A<String>() as java.util.List<String>
expectUoe { a.add("") }
expectUoe { a.remove("") }
expectUoe { a.addAll(a) }
expectUoe { a.addAll(0, a) }
expectUoe { a.removeAll(a) }
expectUoe { a.retainAll(a) }
expectUoe { a.clear() }
expectUoe { a.add(0, "") }
expectUoe { a.set(0, "") }
expectUoe { a.remove(0) }
a.listIterator()
a.listIterator(0)
a.subList(0, 0)
val b = B() as java.util.List<String>
expectUoe { b.add("") }
expectUoe { b.remove("") }
expectUoe { b.addAll(b) }
expectUoe { b.addAll(0, b) }
expectUoe { b.removeAll(b) }
expectUoe { b.retainAll(b) }
expectUoe { b.clear() }
expectUoe { b.add(0, "") }
expectUoe { b.set(0, "") }
expectUoe { b.remove(0) }
b.listIterator()
b.listIterator(0)
b.subList(0, 0)
return "OK"
}