Files
kotlin-fork/compiler/testData/codegen/box/collections/noStubsInJavaSuperClass.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

69 lines
2.4 KiB
Kotlin
Vendored

// TARGET_BACKEND: JVM
// FILE: B.java
public abstract class B<E> extends A<E> implements L<E> {
public String callIndexAdd(int x) {
add(0, null);
return null;
}
}
// FILE: main.kt
open class A<T> : Collection<T> {
override val size: Int
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
override fun contains(element: T): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun containsAll(elements: Collection<T>): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun isEmpty(): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun iterator(): Iterator<T> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
interface L<Q> : List<Q>
// 'add(Int; Object)' method must be present in C though it has supeclass that is subclass of List
class C<F> : B<F>() {
override fun get(index: Int): F {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun indexOf(element: F): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun lastIndexOf(element: F): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun listIterator(): ListIterator<F> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun listIterator(index: Int): ListIterator<F> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun subList(fromIndex: Int, toIndex: Int): List<F> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
fun box() = try {
C<String>().callIndexAdd(1)
throw RuntimeException("fail 1")
} catch (e: UnsupportedOperationException) {
if (e.message != "Operation is not supported for read-only collection") throw RuntimeException("fail 2")
"OK"
}