JVM_IR KT-49765 bridge for throwing stub should just throw UOE

This commit is contained in:
Dmitry Petrov
2021-12-15 19:10:47 +03:00
committed by teamcity
parent 3f22321643
commit 8c71e38c92
17 changed files with 560 additions and 13 deletions
@@ -0,0 +1,39 @@
// TARGET_BACKEND: JVM
// FILE: derivedEmptyListAdd.kt
open class EmptyListBase<T> : List<T>, RandomAccess {
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun contains(element: T): Boolean = false
override fun containsAll(elements: Collection<T>): Boolean = elements.isEmpty()
override fun get(index: Int): T = null!!
override fun indexOf(element: T): Int = -1
override fun lastIndexOf(element: T): Int = -1
override fun iterator(): Iterator<T> = null!!
override fun listIterator(): ListIterator<T> = null!!
override fun listIterator(index: Int): ListIterator<T> = null!!
override fun subList(fromIndex: Int, toIndex: Int): List<T> = null!!
}
object EmptyList : EmptyListBase<Nothing>()
fun box(): String {
try {
J.add()
return "Fail: no exception is thrown from J.add()"
} catch (e: UnsupportedOperationException) {
return "OK"
} catch (e: Throwable) {
throw AssertionError("Fail: incorrect exception is thrown from J.add()", e)
}
}
// FILE: J.java
public class J {
public static void add() {
EmptyList.INSTANCE.add("");
}
}
@@ -0,0 +1,46 @@
// TARGET_BACKEND: JVM
// MODULE: lib
// FILE: RandomAccessList.kt
abstract class RandomAccessList<T> : List<T>, RandomAccess
// MODULE: main(lib)
// FILE: derivedEmptyListSeveralModulesAdd.kt
open class EmptyListBase<T> : RandomAccessList<T>() {
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun contains(element: T): Boolean = false
override fun containsAll(elements: Collection<T>): Boolean = elements.isEmpty()
override fun get(index: Int): T = null!!
override fun indexOf(element: T): Int = -1
override fun lastIndexOf(element: T): Int = -1
override fun iterator(): Iterator<T> = null!!
override fun listIterator(): ListIterator<T> = null!!
override fun listIterator(index: Int): ListIterator<T> = null!!
override fun subList(fromIndex: Int, toIndex: Int): List<T> = null!!
}
object EmptyList : EmptyListBase<Nothing>()
fun box(): String {
try {
J.add()
return "Fail: no exception is thrown from J.add()"
} catch (e: UnsupportedOperationException) {
return "OK"
} catch (e: Throwable) {
throw AssertionError("Fail: incorrect exception is thrown from J.add()", e)
}
}
// FILE: J.java
public class J {
public static void add() {
EmptyList.INSTANCE.add("");
}
}
@@ -0,0 +1,39 @@
// TARGET_BACKEND: JVM
// FILE: derivedEmptyStringListAdd.kt
open class EmptyListBase<T : CharSequence> : List<T>, RandomAccess {
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun contains(element: T): Boolean = false
override fun containsAll(elements: Collection<T>): Boolean = elements.isEmpty()
override fun get(index: Int): T = null!!
override fun indexOf(element: T): Int = -1
override fun lastIndexOf(element: T): Int = -1
override fun iterator(): Iterator<T> = null!!
override fun listIterator(): ListIterator<T> = null!!
override fun listIterator(index: Int): ListIterator<T> = null!!
override fun subList(fromIndex: Int, toIndex: Int): List<T> = null!!
}
object EmptyStringList : EmptyListBase<String>()
fun box(): String {
try {
J.add()
return "Fail: no exception is thrown from J.add()"
} catch (e: UnsupportedOperationException) {
return "OK"
} catch (e: Throwable) {
throw AssertionError("Fail: incorrect exception is thrown from J.add()", e)
}
}
// FILE: J.java
public class J {
public static void add() {
EmptyStringList.INSTANCE.add("");
}
}
@@ -0,0 +1,37 @@
// TARGET_BACKEND: JVM
// FILE: emptyListAdd.kt
object EmptyList : List<Nothing>, RandomAccess {
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun contains(element: Nothing): Boolean = false
override fun containsAll(elements: Collection<Nothing>): Boolean = elements.isEmpty()
override fun get(index: Int): Nothing = null!!
override fun indexOf(element: Nothing): Int = -1
override fun lastIndexOf(element: Nothing): Int = -1
override fun iterator(): Iterator<Nothing> = null!!
override fun listIterator(): ListIterator<Nothing> = null!!
override fun listIterator(index: Int): ListIterator<Nothing> = null!!
override fun subList(fromIndex: Int, toIndex: Int): List<Nothing> = null!!
}
fun box(): String {
try {
J.add()
return "Fail: no exception is thrown from J.add()"
} catch (e: UnsupportedOperationException) {
return "OK"
} catch (e: Throwable) {
throw AssertionError("Fail: incorrect exception is thrown from J.add()", e)
}
}
// FILE: J.java
public class J {
public static void add() {
EmptyList.INSTANCE.add("");
}
}
@@ -0,0 +1,37 @@
// TARGET_BACKEND: JVM
// FILE: emptyListAddWithIndex.kt
object EmptyList : List<Nothing>, RandomAccess {
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun contains(element: Nothing): Boolean = false
override fun containsAll(elements: Collection<Nothing>): Boolean = elements.isEmpty()
override fun get(index: Int): Nothing = null!!
override fun indexOf(element: Nothing): Int = -1
override fun lastIndexOf(element: Nothing): Int = -1
override fun iterator(): Iterator<Nothing> = null!!
override fun listIterator(): ListIterator<Nothing> = null!!
override fun listIterator(index: Int): ListIterator<Nothing> = null!!
override fun subList(fromIndex: Int, toIndex: Int): List<Nothing> = null!!
}
fun box(): String {
try {
J.test()
return "Fail: no exception is thrown from J.add()"
} catch (e: UnsupportedOperationException) {
return "OK"
} catch (e: Throwable) {
throw AssertionError("Fail: incorrect exception is thrown from J.add()", e)
}
}
// FILE: J.java
public class J {
public static void test() {
EmptyList.INSTANCE.add(0, "");
}
}
@@ -0,0 +1,37 @@
// TARGET_BACKEND: JVM
// FILE: emptyListSet.kt
object EmptyList : List<Nothing>, RandomAccess {
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun contains(element: Nothing): Boolean = false
override fun containsAll(elements: Collection<Nothing>): Boolean = elements.isEmpty()
override fun get(index: Int): Nothing = null!!
override fun indexOf(element: Nothing): Int = -1
override fun lastIndexOf(element: Nothing): Int = -1
override fun iterator(): Iterator<Nothing> = null!!
override fun listIterator(): ListIterator<Nothing> = null!!
override fun listIterator(index: Int): ListIterator<Nothing> = null!!
override fun subList(fromIndex: Int, toIndex: Int): List<Nothing> = null!!
}
fun box(): String {
try {
J.test()
return "Fail: no exception is thrown from J.add()"
} catch (e: UnsupportedOperationException) {
return "OK"
} catch (e: Throwable) {
throw AssertionError("Fail: incorrect exception is thrown from J.add()", e)
}
}
// FILE: J.java
public class J {
public static void test() {
EmptyList.INSTANCE.set(0, "");
}
}
@@ -0,0 +1,40 @@
// TARGET_BACKEND: JVM
// FULL_JDK
// FILE: emptyStringListAdd.kt
object EmptyStringList : List<String> {
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun contains(element: String): Boolean = false
override fun containsAll(elements: Collection<String>): Boolean = elements.isEmpty()
override fun get(index: Int): String = null!!
override fun indexOf(element: String): Int = -1
override fun lastIndexOf(element: String): Int = -1
override fun iterator(): Iterator<String> = null!!
override fun listIterator(): ListIterator<String> = null!!
override fun listIterator(index: Int): ListIterator<String> = null!!
override fun subList(fromIndex: Int, toIndex: Int): List<String> = null!!
}
fun box(): String {
try {
J.add42(EmptyStringList)
return "Fail: no exception is thrown from J.add42(list)"
} catch (e: UnsupportedOperationException) {
return "OK"
} catch (e: Throwable) {
throw AssertionError("Fail: incorrect exception is thrown from J.add42(list)", e)
}
}
// FILE: J.java
import java.util.*;
public class J {
public static void add42(List list) {
list.add(42);
}
}