Merge boxWithStdlib testData into box, delete BoxWithStdlib test

This commit is contained in:
Alexander Udalov
2016-03-07 13:36:14 +03:00
committed by Alexander Udalov
parent 22bfc9786a
commit 06a67e6602
535 changed files with 3520 additions and 3871 deletions
@@ -0,0 +1,128 @@
// WITH_RUNTIME
import java.util.*
class Itr : Iterator<String> by ArrayList<String>().iterator()
class MItr : MutableIterator<String> by ArrayList<String>().iterator()
class LItr : ListIterator<String> by ArrayList<String>().listIterator()
class MLItr : MutableListIterator<String> by ArrayList<String>().listIterator()
class It : Iterable<String> by ArrayList<String>()
class MIt : MutableIterable<String> by ArrayList<String>()
class C : Collection<String> by ArrayList<String>()
class MC : MutableCollection<String> by ArrayList<String>()
class L : List<String> by ArrayList<String>()
class ML : MutableList<String> by ArrayList<String>()
class S : Set<String> by HashSet<String>()
class MS : MutableSet<String> by HashSet<String>()
class M : Map<String, String> by HashMap<String, String>()
class MM : MutableMap<String, String> by HashMap<String, String>()
class ME : Map.Entry<String, String> {
override val key: String get() = throw UnsupportedOperationException()
override val value: String get() = throw UnsupportedOperationException()
}
class MME : MutableMap.MutableEntry<String, String> {
override val key: String get() = throw UnsupportedOperationException()
override val value: String get() = throw UnsupportedOperationException()
override fun setValue(value: String): String = throw UnsupportedOperationException()
}
inline fun asFailsWithCCE(operation: String, block: () -> Unit) {
try {
block()
}
catch (e: java.lang.ClassCastException) {
return
}
catch (e: Throwable) {
throw AssertionError("$operation: should throw ClassCastException, got $e")
}
throw AssertionError("$operation: should throw ClassCastException, no exception thrown")
}
inline fun asSucceeds(operation: String, block: () -> Unit) {
try {
block()
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
}
fun box(): String {
val itr = Itr() as Any
val mitr = MItr()
asFailsWithCCE("itr as MutableIterator") { itr as MutableIterator<*> }
asSucceeds("mitr as MutableIterator") { mitr as MutableIterator<*> }
val litr = LItr() as Any
val mlitr = MLItr()
asFailsWithCCE("litr as MutableIterator") { litr as MutableIterator<*> }
asFailsWithCCE("litr as MutableListIterator") { litr as MutableListIterator<*> }
asSucceeds("mlitr as MutableIterator") { mlitr as MutableIterator<*> }
asSucceeds("mlitr as MutableListIterator") { mlitr as MutableListIterator<*> }
val it = It() as Any
val mit = MIt()
val arrayList = ArrayList<String>()
asFailsWithCCE("it as MutableIterable") { it as MutableIterable<*> }
asSucceeds("mit as MutableIterable") { mit as MutableIterable<*> }
asSucceeds("arrayList as MutableIterable") { arrayList as MutableIterable<*> }
val coll = C() as Any
val mcoll = MC()
asFailsWithCCE("coll as MutableIterable") { coll as MutableIterable<*> }
asFailsWithCCE("coll as MutableCollection") { coll as MutableCollection<*> }
asSucceeds("mcoll as MutableIterable") { mcoll as MutableIterable<*> }
asSucceeds("mcoll as MutableCollection") { mcoll as MutableCollection<*> }
asSucceeds("arrayList as MutableCollection") { arrayList as MutableCollection<*> }
val list = L() as Any
val mlist = ML()
asFailsWithCCE("list as MutableIterable") { list as MutableIterable<*> }
asFailsWithCCE("list as MutableCollection") { list as MutableCollection<*> }
asFailsWithCCE("list as MutableList") { list as MutableList<*> }
asSucceeds("mlist as MutableIterable") { mlist as MutableIterable<*> }
asSucceeds("mlist as MutableCollection") { mlist as MutableCollection<*> }
asSucceeds("mlist as MutableList") { mlist as MutableList<*> }
val set = S() as Any
val mset = MS()
val hashSet = HashSet<String>()
asFailsWithCCE("set as MutableIterable") { set as MutableIterable<*> }
asFailsWithCCE("set as MutableCollection") { set as MutableCollection<*> }
asFailsWithCCE("set as MutableSet") { set as MutableSet<*> }
asSucceeds("mset as MutableIterable") { mset as MutableIterable<*> }
asSucceeds("mset as MutableCollection") { mset as MutableCollection<*> }
asSucceeds("mset as MutableSet") { mset as MutableSet<*> }
asSucceeds("hashSet as MutableSet") { hashSet as MutableSet<*> }
val map = M() as Any
val mmap = MM()
val hashMap = HashMap<String, String>()
asFailsWithCCE("map as MutableMap") { map as MutableMap<*, *> }
asSucceeds("mmap as MutableMap") { mmap as MutableMap<*, *> }
val entry = ME() as Any
val mentry = MME()
asFailsWithCCE("entry as MutableMap.MutableEntry") { entry as MutableMap.MutableEntry<*, *> }
asSucceeds("mentry as MutableMap.MutableEntry") { mentry as MutableMap.MutableEntry<*, *> }
hashMap[""] = ""
val hashMapEntry = hashMap.entries.first()
asSucceeds("hashMapEntry as MutableMap.MutableEntry") { hashMapEntry as MutableMap.MutableEntry<*, *> }
return "OK"
}
@@ -0,0 +1,111 @@
// WITH_RUNTIME
import java.util.*
class Itr : Iterator<String> by ArrayList<String>().iterator()
class MItr : MutableIterator<String> by ArrayList<String>().iterator()
class LItr : ListIterator<String> by ArrayList<String>().listIterator()
class MLItr : MutableListIterator<String> by ArrayList<String>().listIterator()
class It : Iterable<String> by ArrayList<String>()
class MIt : MutableIterable<String> by ArrayList<String>()
class C : Collection<String> by ArrayList<String>()
class MC : MutableCollection<String> by ArrayList<String>()
class L : List<String> by ArrayList<String>()
class ML : MutableList<String> by ArrayList<String>()
class S : Set<String> by HashSet<String>()
class MS : MutableSet<String> by HashSet<String>()
class M : Map<String, String> by HashMap<String, String>()
class MM : MutableMap<String, String> by HashMap<String, String>()
class ME : Map.Entry<String, String> {
override val key: String get() = throw UnsupportedOperationException()
override val value: String get() = throw UnsupportedOperationException()
}
class MME : MutableMap.MutableEntry<String, String> {
override val key: String get() = throw UnsupportedOperationException()
override val value: String get() = throw UnsupportedOperationException()
override fun setValue(value: String): String = throw UnsupportedOperationException()
}
fun box(): String {
val itr = Itr() as Any
val mitr = MItr()
assert(itr !is MutableIterator<*>) { "Itr should satisfy '!is MutableIterator'" }
assert(mitr is MutableIterator<*>) { "MItr should satisfy 'is MutableIterator'" }
val litr = LItr() as Any
val mlitr = MLItr()
assert(litr !is MutableIterator<*>) { "LItr should satisfy '!is MutableIterator'" }
assert(litr !is MutableListIterator<*>) { "LItr should satisfy '!is MutableListIterator'" }
assert(mlitr is MutableListIterator<*>) { "MLItr should satisfy 'is MutableListIterator'" }
val it = It() as Any
val mit = MIt()
val arrayList = ArrayList<String>()
assert(it !is MutableIterable<*>) { "It should satisfy '!is MutableIterable'" }
assert(mit is MutableIterable<*>) { "MIt should satisfy 'is MutableIterable'" }
assert(arrayList is MutableIterable<*>) { "ArrayList should satisfy 'is MutableIterable'" }
val coll = C() as Any
val mcoll = MC()
assert(coll !is MutableCollection<*>) { "C should satisfy '!is MutableCollection'" }
assert(coll !is MutableIterable<*>) { "C should satisfy '!is MutableIterable'" }
assert(mcoll is MutableCollection<*>) { "MC should satisfy 'is MutableCollection'" }
assert(mcoll is MutableIterable<*>) { "MC should satisfy 'is MutableIterable'" }
assert(arrayList is MutableCollection<*>) { "ArrayList should satisfy 'is MutableCollection'" }
val list = L() as Any
val mlist = ML()
assert(list !is MutableList<*>) { "L should satisfy '!is MutableList'" }
assert(list !is MutableCollection<*>) { "L should satisfy '!is MutableCollection'" }
assert(list !is MutableIterable<*>) { "L should satisfy '!is MutableIterable'" }
assert(mlist is MutableList<*>) { "ML should satisfy 'is MutableList'" }
assert(mlist is MutableCollection<*>) { "ML should satisfy 'is MutableCollection'" }
assert(mlist is MutableIterable<*>) { "ML should satisfy 'is MutableIterable'" }
assert(arrayList is MutableList<*>) { "ArrayList should satisfy 'is MutableList'" }
val set = S() as Any
val mset = MS()
val hashSet = HashSet<String>()
assert(set !is MutableSet<*>) { "S should satisfy '!is MutableSet'" }
assert(set !is MutableCollection<*>) { "S should satisfy '!is MutableCollection'" }
assert(set !is MutableIterable<*>) { "S should satisfy '!is MutableIterable'" }
assert(mset is MutableSet<*>) { "MS should satisfy 'is MutableSet'" }
assert(mset is MutableCollection<*>) { "MS should satisfy 'is MutableCollection'" }
assert(mset is MutableIterable<*>) { "MS should satisfy 'is MutableIterable'" }
assert(hashSet is MutableSet<*>) { "HashSet should satisfy 'is MutableSet'" }
assert(hashSet is MutableCollection<*>) { "HashSet should satisfy 'is MutableCollection'" }
assert(hashSet is MutableIterable<*>) { "HashSet should satisfy 'is MutableIterable'" }
val map = M() as Any
val mmap = MM()
val hashMap = HashMap<String, String>()
assert(map !is MutableMap<*, *>) { "M should satisfy '!is MutableMap'" }
assert(mmap is MutableMap<*, *>) { "MM should satisfy 'is MutableMap'"}
assert(hashMap is MutableMap<*, *>) { "HashMap should satisfy 'is MutableMap'" }
val entry = ME() as Any
val mentry = MME()
hashMap[""] = ""
val hashMapEntry = hashMap.entries.first()
assert(entry !is MutableMap.MutableEntry<*, *>) { "ME should satisfy '!is MutableMap.MutableEntry'"}
assert(mentry is MutableMap.MutableEntry<*, *>) { "MME should satisfy 'is MutableMap.MutableEntry'"}
assert(hashMapEntry is MutableMap.MutableEntry<*, *>) { "HashMap.Entry should satisfy 'is MutableMap.MutableEntry'"}
assert((mlist as Any) !is MutableSet<*>) { "ML !is MutableSet" }
assert((mlist as Any) !is MutableIterator<*>) { "ML !is MutableIterator" }
return "OK"
}
@@ -0,0 +1,57 @@
// WITH_RUNTIME
abstract class Itr : Iterator<String>
abstract class MItr : MutableIterator<String>
abstract class LItr : ListIterator<String>
abstract class MLItr : MutableListIterator<String>
abstract class It : Iterable<String>
abstract class MIt : MutableIterable<String>
abstract class C : Collection<String>
abstract class MC : MutableCollection<String>
abstract class L : List<String>
abstract class ML : MutableList<String>
abstract class S : Set<String>
abstract class MS : MutableSet<String>
abstract class M : Map<String, String>
abstract class MM : MutableMap<String, String>
abstract class ME : Map.Entry<String, String>
abstract class MME : MutableMap.MutableEntry<String, String>
abstract class L2 : L()
abstract class ML2 : ML()
abstract class Weird : Iterator<String>, MutableList<String>
fun expectInterfaces(jClass: Class<*>, expectedInterfaceNames: Set<String>) {
val actualInterfaceNames = jClass.getInterfaces().mapTo(linkedSetOf<String>()) { it.name }
assert(actualInterfaceNames == expectedInterfaceNames) {
"${jClass.name}: interfaces: expected: $expectedInterfaceNames; actual: $actualInterfaceNames"
}
}
fun box(): String {
expectInterfaces(Itr::class.java, setOf("java.util.Iterator", "kotlin.jvm.internal.markers.KMappedMarker"))
expectInterfaces(MItr::class.java, setOf("java.util.Iterator", "kotlin.jvm.internal.markers.KMutableIterator"))
expectInterfaces(LItr::class.java, setOf("java.util.ListIterator", "kotlin.jvm.internal.markers.KMappedMarker"))
expectInterfaces(MLItr::class.java, setOf("java.util.ListIterator", "kotlin.jvm.internal.markers.KMutableListIterator"))
expectInterfaces(It::class.java, setOf("java.lang.Iterable", "kotlin.jvm.internal.markers.KMappedMarker"))
expectInterfaces(MIt::class.java, setOf("java.lang.Iterable", "kotlin.jvm.internal.markers.KMutableIterable"))
expectInterfaces(C::class.java, setOf("java.util.Collection", "kotlin.jvm.internal.markers.KMappedMarker"))
expectInterfaces(MC::class.java, setOf("java.util.Collection", "kotlin.jvm.internal.markers.KMutableCollection"))
expectInterfaces(L::class.java, setOf("java.util.List", "kotlin.jvm.internal.markers.KMappedMarker"))
expectInterfaces(ML::class.java, setOf("java.util.List", "kotlin.jvm.internal.markers.KMutableList"))
expectInterfaces(S::class.java, setOf("java.util.Set", "kotlin.jvm.internal.markers.KMappedMarker"))
expectInterfaces(MS::class.java, setOf("java.util.Set", "kotlin.jvm.internal.markers.KMutableSet"))
expectInterfaces(M::class.java, setOf("java.util.Map", "kotlin.jvm.internal.markers.KMappedMarker"))
expectInterfaces(MM::class.java, setOf("java.util.Map", "kotlin.jvm.internal.markers.KMutableMap"))
expectInterfaces(ME::class.java, setOf("java.util.Map\$Entry", "kotlin.jvm.internal.markers.KMappedMarker"))
expectInterfaces(MME::class.java, setOf("java.util.Map\$Entry", "kotlin.jvm.internal.markers.KMutableMap\$Entry"))
expectInterfaces(L2::class.java, setOf<String>())
expectInterfaces(ML2::class.java, setOf<String>())
expectInterfaces(Weird::class.java,
setOf("java.util.Iterator", "kotlin.jvm.internal.markers.KMappedMarker",
"java.util.List", "kotlin.jvm.internal.markers.KMutableList"))
return "OK"
}
@@ -0,0 +1,130 @@
// WITH_RUNTIME
import java.util.*
class Itr : Iterator<String> by ArrayList<String>().iterator()
class MItr : MutableIterator<String> by ArrayList<String>().iterator()
class LItr : ListIterator<String> by ArrayList<String>().listIterator()
class MLItr : MutableListIterator<String> by ArrayList<String>().listIterator()
class It : Iterable<String> by ArrayList<String>()
class MIt : MutableIterable<String> by ArrayList<String>()
class C : Collection<String> by ArrayList<String>()
class MC : MutableCollection<String> by ArrayList<String>()
class L : List<String> by ArrayList<String>()
class ML : MutableList<String> by ArrayList<String>()
class S : Set<String> by HashSet<String>()
class MS : MutableSet<String> by HashSet<String>()
class M : Map<String, String> by HashMap<String, String>()
class MM : MutableMap<String, String> by HashMap<String, String>()
class ME : Map.Entry<String, String> {
override val key: String get() = throw UnsupportedOperationException()
override val value: String get() = throw UnsupportedOperationException()
}
class MME : MutableMap.MutableEntry<String, String> {
override val key: String get() = throw UnsupportedOperationException()
override val value: String get() = throw UnsupportedOperationException()
override fun setValue(value: String): String = throw UnsupportedOperationException()
}
inline fun <reified T> reifiedAsSucceeds(x: Any, operation: String) {
try {
x as T
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
}
inline fun <reified T> reifiedAsFailsWithCCE(x: Any, operation: String) {
try {
x as T
}
catch (e: java.lang.ClassCastException) {
return
}
catch (e: Throwable) {
throw AssertionError("$operation: should throw ClassCastException, got $e")
}
throw AssertionError("$operation: should fail with CCE, no exception thrown")
}
fun box(): String {
val itr = Itr() as Any
val mitr = MItr()
reifiedAsFailsWithCCE<MutableIterator<*>>(itr, "reifiedAs<MutableIterator<*>>(itr)")
reifiedAsSucceeds<MutableIterator<*>>(mitr, "reifiedAs<MutableIterator<*>>(mitr)")
val litr = LItr() as Any
val mlitr = MLItr()
reifiedAsFailsWithCCE<MutableIterator<*>>(litr, "reifiedAs<MutableIterator<*>>(litr)")
reifiedAsFailsWithCCE<MutableListIterator<*>>(litr, "reifiedAs<MutableListIterator<*>>(litr)")
reifiedAsSucceeds<MutableListIterator<*>>(mlitr, "reifiedAs<MutableListIterator<*>>(mlitr)")
val it = It() as Any
val mit = MIt()
val arrayList = ArrayList<String>()
reifiedAsFailsWithCCE<MutableIterable<*>>(it, "reifiedAs<MutableIterable<*>>(it)")
reifiedAsSucceeds<MutableIterable<*>>(mit, "reifiedAs<MutableIterable<*>>(mit)")
reifiedAsSucceeds<MutableIterable<*>>(arrayList, "reifiedAs<MutableIterable<*>>(arrayList)")
val coll = C() as Any
val mcoll = MC()
reifiedAsFailsWithCCE<MutableCollection<*>>(coll, "reifiedAs<MutableCollection<*>>(coll)")
reifiedAsFailsWithCCE<MutableIterable<*>>(coll, "reifiedAs<MutableIterable<*>>(coll)")
reifiedAsSucceeds<MutableCollection<*>>(mcoll, "reifiedAs<MutableCollection<*>>(mcoll)")
reifiedAsSucceeds<MutableIterable<*>>(mcoll, "reifiedAs<MutableIterable<*>>(mcoll)")
reifiedAsSucceeds<MutableCollection<*>>(arrayList, "reifiedAs<MutableCollection<*>>(arrayList)")
val list = L() as Any
val mlist = ML()
reifiedAsFailsWithCCE<MutableList<*>>(list, "reifiedAs<MutableList<*>>(list)")
reifiedAsFailsWithCCE<MutableCollection<*>>(list, "reifiedAs<MutableCollection<*>>(list)")
reifiedAsFailsWithCCE<MutableIterable<*>>(list, "reifiedAs<MutableIterable<*>>(list)")
reifiedAsSucceeds<MutableList<*>>(mlist, "reifiedAs<MutableList<*>>(mlist)")
reifiedAsSucceeds<MutableCollection<*>>(mlist, "reifiedAs<MutableCollection<*>>(mlist)")
reifiedAsSucceeds<MutableIterable<*>>(mlist, "reifiedAs<MutableIterable<*>>(mlist)")
reifiedAsSucceeds<MutableList<*>>(arrayList, "reifiedAs<MutableList<*>>(arrayList)")
val set = S() as Any
val mset = MS()
val hashSet = HashSet<String>()
reifiedAsFailsWithCCE<MutableSet<*>>(set, "reifiedAs<MutableSet<*>>(set)")
reifiedAsFailsWithCCE<MutableCollection<*>>(set, "reifiedAs<MutableCollection<*>>(set)")
reifiedAsFailsWithCCE<MutableIterable<*>>(set, "reifiedAs<MutableIterable<*>>(set)")
reifiedAsSucceeds<MutableSet<*>>(mset, "reifiedAs<MutableSet<*>>(mset)")
reifiedAsSucceeds<MutableCollection<*>>(mset, "reifiedAs<MutableCollection<*>>(mset)")
reifiedAsSucceeds<MutableIterable<*>>(mset, "reifiedAs<MutableIterable<*>>(mset)")
reifiedAsSucceeds<MutableSet<*>>(hashSet, "reifiedAs<MutableSet<*>>(hashSet)")
reifiedAsSucceeds<MutableCollection<*>>(hashSet, "reifiedAs<MutableCollection<*>>(hashSet)")
reifiedAsSucceeds<MutableIterable<*>>(hashSet, "reifiedAs<MutableIterable<*>>(hashSet)")
val map = M() as Any
val mmap = MM()
val hashMap = HashMap<String, String>()
reifiedAsFailsWithCCE<MutableMap<*, *>>(map, "reifiedAs<MutableMap<*, *>>(map)")
reifiedAsSucceeds<MutableMap<*, *>>(mmap, "reifiedAs<MutableMap<*, *>>(mmap)")
reifiedAsSucceeds<MutableMap<*, *>>(hashMap, "reifiedAs<MutableMap<*, *>>(hashMap)")
val entry = ME() as Any
val mentry = MME()
hashMap[""] = ""
val hashMapEntry = hashMap.entries.first()
reifiedAsFailsWithCCE<MutableMap.MutableEntry<*, *>>(entry, "reifiedAs<MutableMap.MutableEntry<*, *>>(entry)")
reifiedAsSucceeds<MutableMap.MutableEntry<*, *>>(mentry, "reifiedAs<MutableMap.MutableEntry<*, *>>(mentry)")
reifiedAsSucceeds<MutableMap.MutableEntry<*, *>>(hashMapEntry, "reifiedAs<MutableMap.MutableEntry<*, *>>(hashMapEntry)")
return "OK"
}
@@ -0,0 +1,111 @@
// WITH_RUNTIME
import java.util.*
class Itr : Iterator<String> by ArrayList<String>().iterator()
class MItr : MutableIterator<String> by ArrayList<String>().iterator()
class LItr : ListIterator<String> by ArrayList<String>().listIterator()
class MLItr : MutableListIterator<String> by ArrayList<String>().listIterator()
class It : Iterable<String> by ArrayList<String>()
class MIt : MutableIterable<String> by ArrayList<String>()
class C : Collection<String> by ArrayList<String>()
class MC : MutableCollection<String> by ArrayList<String>()
class L : List<String> by ArrayList<String>()
class ML : MutableList<String> by ArrayList<String>()
class S : Set<String> by HashSet<String>()
class MS : MutableSet<String> by HashSet<String>()
class M : Map<String, String> by HashMap<String, String>()
class MM : MutableMap<String, String> by HashMap<String, String>()
class ME : Map.Entry<String, String> {
override val key: String get() = throw UnsupportedOperationException()
override val value: String get() = throw UnsupportedOperationException()
}
class MME : MutableMap.MutableEntry<String, String> {
override val key: String get() = throw UnsupportedOperationException()
override val value: String get() = throw UnsupportedOperationException()
override fun setValue(value: String): String = throw UnsupportedOperationException()
}
inline fun <reified T> reifiedIs(x: Any): Boolean = x is T
inline fun <reified T> reifiedIsNot(x: Any): Boolean = x !is T
fun box(): String {
val itr = Itr() as Any
val mitr = MItr()
assert(reifiedIsNot<MutableIterator<*>>(itr)) { "reifiedIsNot<MutableIterator<*>>(itr)" }
assert(reifiedIs<MutableIterator<*>>(mitr)) { "reifiedIs<MutableIterator<*>>(mitr)" }
val litr = LItr() as Any
val mlitr = MLItr()
assert(reifiedIsNot<MutableIterator<*>>(litr)) { "reifiedIsNot<MutableIterator<*>>(litr)" }
assert(reifiedIsNot<MutableListIterator<*>>(litr)) { "reifiedIsNot<MutableListIterator<*>>(litr)" }
assert(reifiedIs<MutableListIterator<*>>(mlitr)) { "reifiedIs<MutableListIterator<*>>(mlitr)" }
val it = It() as Any
val mit = MIt()
val arrayList = ArrayList<String>()
assert(reifiedIsNot<MutableIterable<*>>(it)) { "reifiedIsNot<MutableIterable<*>>(it)" }
assert(reifiedIs<MutableIterable<*>>(mit)) { "reifiedIs<MutableIterable<*>>(mit)" }
assert(reifiedIs<MutableIterable<*>>(arrayList)) { "reifiedIs<MutableIterable<*>>(arrayList)" }
val coll = C() as Any
val mcoll = MC()
assert(reifiedIsNot<MutableCollection<*>>(coll)) { "reifiedIsNot<MutableCollection<*>>(coll)" }
assert(reifiedIsNot<MutableIterable<*>>(coll)) { "reifiedIsNot<MutableIterable<*>>(coll)" }
assert(reifiedIs<MutableCollection<*>>(mcoll)) { "reifiedIs<MutableCollection<*>>(mcoll)" }
assert(reifiedIs<MutableIterable<*>>(mcoll)) { "reifiedIs<MutableIterable<*>>(mcoll)" }
assert(reifiedIs<MutableCollection<*>>(arrayList)) { "reifiedIs<MutableCollection<*>>(arrayList)" }
val list = L() as Any
val mlist = ML()
assert(reifiedIsNot<MutableList<*>>(list)) { "reifiedIsNot<MutableList<*>>(list)" }
assert(reifiedIsNot<MutableCollection<*>>(list)) { "reifiedIsNot<MutableCollection<*>>(list)" }
assert(reifiedIsNot<MutableIterable<*>>(list)) { "reifiedIsNot<MutableIterable<*>>(list)" }
assert(reifiedIs<MutableList<*>>(mlist)) { "reifiedIs<MutableList<*>>(mlist)" }
assert(reifiedIs<MutableCollection<*>>(mlist)) { "reifiedIs<MutableCollection<*>>(mlist)" }
assert(reifiedIs<MutableIterable<*>>(mlist)) { "reifiedIs<MutableIterable<*>>(mlist)" }
assert(reifiedIs<MutableList<*>>(arrayList)) { "reifiedIs<MutableList<*>>(arrayList)" }
val set = S() as Any
val mset = MS()
val hashSet = HashSet<String>()
assert(reifiedIsNot<MutableSet<*>>(set)) { "reifiedIsNot<MutableSet<*>>(set)" }
assert(reifiedIsNot<MutableCollection<*>>(set)) { "reifiedIsNot<MutableCollection<*>>(set)" }
assert(reifiedIsNot<MutableIterable<*>>(set)) { "reifiedIsNot<MutableIterable<*>>(set)" }
assert(reifiedIs<MutableSet<*>>(mset)) { "reifiedIs<MutableSet<*>>(mset)" }
assert(reifiedIs<MutableCollection<*>>(mset)) { "reifiedIs<MutableCollection<*>>(mset)" }
assert(reifiedIs<MutableIterable<*>>(mset)) { "reifiedIs<MutableIterable<*>>(mset)" }
assert(reifiedIs<MutableSet<*>>(hashSet)) { "reifiedIs<MutableSet<*>>(hashSet)" }
assert(reifiedIs<MutableCollection<*>>(hashSet)) { "reifiedIs<MutableCollection<*>>(hashSet)" }
assert(reifiedIs<MutableIterable<*>>(hashSet)) { "reifiedIs<MutableIterable<*>>(hashSet)" }
val map = M() as Any
val mmap = MM()
val hashMap = HashMap<String, String>()
assert(reifiedIsNot<MutableMap<*, *>>(map)) { "reifiedIsNot<MutableMap<*, *>>(map)" }
assert(reifiedIs<MutableMap<*, *>>(mmap)) { "reifiedIs<MutableMap<*, *>>(mmap)"}
assert(reifiedIs<MutableMap<*, *>>(hashMap)) { "reifiedIs<MutableMap<*, *>>(hashMap)" }
val entry = ME() as Any
val mentry = MME()
hashMap[""] = ""
val hashMapEntry = hashMap.entries.first()
assert(reifiedIsNot<MutableMap.MutableEntry<*, *>>(entry)) { "reifiedIsNot<MutableMap.MutableEntry<*, *>>(entry)"}
assert(reifiedIs<MutableMap.MutableEntry<*, *>>(mentry)) { "reifiedIs<MutableMap.MutableEntry<*, *>>(mentry)"}
assert(reifiedIs<MutableMap.MutableEntry<*, *>>(hashMapEntry)) { "reifiedIs<MutableMap.MutableEntry<*, *>>(hashMapEntry)"}
return "OK"
}
@@ -0,0 +1,141 @@
// WITH_RUNTIME
import java.util.*
class Itr : Iterator<String> by ArrayList<String>().iterator()
class MItr : MutableIterator<String> by ArrayList<String>().iterator()
class LItr : ListIterator<String> by ArrayList<String>().listIterator()
class MLItr : MutableListIterator<String> by ArrayList<String>().listIterator()
class It : Iterable<String> by ArrayList<String>()
class MIt : MutableIterable<String> by ArrayList<String>()
class C : Collection<String> by ArrayList<String>()
class MC : MutableCollection<String> by ArrayList<String>()
class L : List<String> by ArrayList<String>()
class ML : MutableList<String> by ArrayList<String>()
class S : Set<String> by HashSet<String>()
class MS : MutableSet<String> by HashSet<String>()
class M : Map<String, String> by HashMap<String, String>()
class MM : MutableMap<String, String> by HashMap<String, String>()
class ME : Map.Entry<String, String> {
override val key: String get() = throw UnsupportedOperationException()
override val value: String get() = throw UnsupportedOperationException()
}
class MME : MutableMap.MutableEntry<String, String> {
override val key: String get() = throw UnsupportedOperationException()
override val value: String get() = throw UnsupportedOperationException()
override fun setValue(value: String): String = throw UnsupportedOperationException()
}
inline fun <reified T> reifiedSafeAsReturnsNonNull(x: Any?, operation: String) {
val y = try {
x as? T
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
if (y == null) {
throw AssertionError("$operation: should return non-null, got null")
}
}
inline fun <reified T> reifiedSafeAsReturnsNull(x: Any?, operation: String) {
val y = try {
x as? T
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
if (y != null) {
throw AssertionError("$operation: should return null, got $y")
}
}
fun box(): String {
val itr = Itr() as Any
val mitr = MItr()
reifiedSafeAsReturnsNull<MutableIterator<*>>(itr, "reifiedSafeAs<MutableIterator<*>>(itr)")
reifiedSafeAsReturnsNonNull<MutableIterator<*>>(mitr, "reifiedSafeAs<MutableIterator<*>>(mitr)")
val litr = LItr() as Any
val mlitr = MLItr()
reifiedSafeAsReturnsNull<MutableIterator<*>>(litr, "reifiedSafeAs<MutableIterator<*>>(litr)")
reifiedSafeAsReturnsNull<MutableListIterator<*>>(litr, "reifiedSafeAs<MutableListIterator<*>>(litr)")
reifiedSafeAsReturnsNonNull<MutableListIterator<*>>(mlitr, "reifiedSafeAs<MutableListIterator<*>>(mlitr)")
val it = It() as Any
val mit = MIt()
val arrayList = ArrayList<String>()
reifiedSafeAsReturnsNull<MutableIterable<*>>(it, "reifiedSafeAs<MutableIterable<*>>(it)")
reifiedSafeAsReturnsNonNull<MutableIterable<*>>(mit, "reifiedSafeAs<MutableIterable<*>>(mit)")
reifiedSafeAsReturnsNonNull<MutableIterable<*>>(arrayList, "reifiedSafeAs<MutableIterable<*>>(arrayList)")
val coll = C() as Any
val mcoll = MC()
reifiedSafeAsReturnsNull<MutableCollection<*>>(coll, "reifiedSafeAs<MutableCollection<*>>(coll)")
reifiedSafeAsReturnsNull<MutableIterable<*>>(coll, "reifiedSafeAs<MutableIterable<*>>(coll)")
reifiedSafeAsReturnsNonNull<MutableCollection<*>>(mcoll, "reifiedSafeAs<MutableCollection<*>>(mcoll)")
reifiedSafeAsReturnsNonNull<MutableIterable<*>>(mcoll, "reifiedSafeAs<MutableIterable<*>>(mcoll)")
reifiedSafeAsReturnsNonNull<MutableCollection<*>>(arrayList, "reifiedSafeAs<MutableCollection<*>>(arrayList)")
val list = L() as Any
val mlist = ML()
reifiedSafeAsReturnsNull<MutableList<*>>(list, "reifiedSafeAs<MutableList<*>>(list)")
reifiedSafeAsReturnsNull<MutableCollection<*>>(list, "reifiedSafeAs<MutableCollection<*>>(list)")
reifiedSafeAsReturnsNull<MutableIterable<*>>(list, "reifiedSafeAs<MutableIterable<*>>(list)")
reifiedSafeAsReturnsNonNull<MutableList<*>>(mlist, "reifiedSafeAs<MutableList<*>>(mlist)")
reifiedSafeAsReturnsNonNull<MutableCollection<*>>(mlist, "reifiedSafeAs<MutableCollection<*>>(mlist)")
reifiedSafeAsReturnsNonNull<MutableIterable<*>>(mlist, "reifiedSafeAs<MutableIterable<*>>(mlist)")
reifiedSafeAsReturnsNonNull<MutableList<*>>(arrayList, "reifiedSafeAs<MutableList<*>>(arrayList)")
val set = S() as Any
val mset = MS()
val hashSet = HashSet<String>()
reifiedSafeAsReturnsNull<MutableSet<*>>(set, "reifiedSafeAs<MutableSet<*>>(set)")
reifiedSafeAsReturnsNull<MutableCollection<*>>(set, "reifiedSafeAs<MutableCollection<*>>(set)")
reifiedSafeAsReturnsNull<MutableIterable<*>>(set, "reifiedSafeAs<MutableIterable<*>>(set)")
reifiedSafeAsReturnsNonNull<MutableSet<*>>(mset, "reifiedSafeAs<MutableSet<*>>(mset)")
reifiedSafeAsReturnsNonNull<MutableCollection<*>>(mset, "reifiedSafeAs<MutableCollection<*>>(mset)")
reifiedSafeAsReturnsNonNull<MutableIterable<*>>(mset, "reifiedSafeAs<MutableIterable<*>>(mset)")
reifiedSafeAsReturnsNonNull<MutableSet<*>>(hashSet, "reifiedSafeAs<MutableSet<*>>(hashSet)")
reifiedSafeAsReturnsNonNull<MutableCollection<*>>(hashSet, "reifiedSafeAs<MutableCollection<*>>(hashSet)")
reifiedSafeAsReturnsNonNull<MutableIterable<*>>(hashSet, "reifiedSafeAs<MutableIterable<*>>(hashSet)")
val map = M() as Any
val mmap = MM()
val hashMap = HashMap<String, String>()
reifiedSafeAsReturnsNull<MutableMap<*, *>>(map, "reifiedSafeAs<MutableMap<*, *>>(map)")
reifiedSafeAsReturnsNonNull<MutableMap<*, *>>(mmap, "reifiedSafeAs<MutableMap<*, *>>(mmap)")
reifiedSafeAsReturnsNonNull<MutableMap<*, *>>(hashMap, "reifiedSafeAs<MutableMap<*, *>>(hashMap)")
val entry = ME() as Any
val mentry = MME()
hashMap[""] = ""
val hashMapEntry = hashMap.entries.first()
reifiedSafeAsReturnsNull<MutableMap.MutableEntry<*, *>>(entry, "reifiedSafeAs<MutableMap.MutableEntry<*, *>>(entry)")
reifiedSafeAsReturnsNonNull<MutableMap.MutableEntry<*, *>>(mentry, "reifiedSafeAs<MutableMap.MutableEntry<*, *>>(mentry)")
reifiedSafeAsReturnsNonNull<MutableMap.MutableEntry<*, *>>(hashMapEntry, "reifiedSafeAs<MutableMap.MutableEntry<*, *>>(hashMapEntry)")
reifiedSafeAsReturnsNull<MutableIterator<*>>(null, "reifiedSafeAs<MutableIterator<*>>(null)")
reifiedSafeAsReturnsNull<MutableListIterator<*>>(null, "reifiedSafeAs<MutableListIterator<*>>(null)")
reifiedSafeAsReturnsNull<MutableIterable<*>>(null, "reifiedSafeAs<MutableIterable<*>>(null)")
reifiedSafeAsReturnsNull<MutableCollection<*>>(null, "reifiedSafeAs<MutableCollection<*>>(null)")
reifiedSafeAsReturnsNull<MutableList<*>>(null, "reifiedSafeAs<MutableList<*>>(null)")
reifiedSafeAsReturnsNull<MutableSet<*>>(null, "reifiedSafeAs<MutableSet<*>>(null)")
reifiedSafeAsReturnsNull<MutableMap<*, *>>(null, "reifiedSafeAs<MutableMap<*, *>>(null)")
reifiedSafeAsReturnsNull<MutableMap.MutableEntry<*, *>>(null, "reifiedSafeAs<MutableMap.MutableEntry<*, *>>(null)")
return "OK"
}
@@ -0,0 +1,139 @@
// WITH_RUNTIME
import java.util.*
class Itr : Iterator<String> by ArrayList<String>().iterator()
class MItr : MutableIterator<String> by ArrayList<String>().iterator()
class LItr : ListIterator<String> by ArrayList<String>().listIterator()
class MLItr : MutableListIterator<String> by ArrayList<String>().listIterator()
class It : Iterable<String> by ArrayList<String>()
class MIt : MutableIterable<String> by ArrayList<String>()
class C : Collection<String> by ArrayList<String>()
class MC : MutableCollection<String> by ArrayList<String>()
class L : List<String> by ArrayList<String>()
class ML : MutableList<String> by ArrayList<String>()
class S : Set<String> by HashSet<String>()
class MS : MutableSet<String> by HashSet<String>()
class M : Map<String, String> by HashMap<String, String>()
class MM : MutableMap<String, String> by HashMap<String, String>()
class ME : Map.Entry<String, String> {
override val key: String get() = throw UnsupportedOperationException()
override val value: String get() = throw UnsupportedOperationException()
}
class MME : MutableMap.MutableEntry<String, String> {
override val key: String get() = throw UnsupportedOperationException()
override val value: String get() = throw UnsupportedOperationException()
override fun setValue(value: String): String = throw UnsupportedOperationException()
}
inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) {
try {
val x = cast()
assert(x == null) { "$operation: should return null, got $x" }
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
}
inline fun safeAsReturnsNonNull(operation: String, cast: () -> Any?) {
try {
val x = cast()
assert(x != null) { "$operation: should return non-null" }
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
}
fun box(): String {
val itr = Itr() as Any
val mitr = MItr()
safeAsReturnsNull("itr as? MutableIterator") { itr as? MutableIterator<*> }
safeAsReturnsNonNull("mitr as? MutableIterator") { mitr as? MutableIterator<*> }
val litr = LItr() as Any
val mlitr = MLItr()
safeAsReturnsNull("litr as? MutableIterator") { litr as? MutableIterator<*> }
safeAsReturnsNull("litr as? MutableListIterator") { litr as? MutableListIterator<*> }
safeAsReturnsNonNull("mlitr as? MutableIterator") { mlitr as? MutableIterator<*> }
safeAsReturnsNonNull("mlitr as? MutableListIterator") { mlitr as? MutableListIterator<*> }
val it = It() as Any
val mit = MIt()
val arrayList = ArrayList<String>()
safeAsReturnsNull("it as? MutableIterable") { it as? MutableIterable<*> }
safeAsReturnsNonNull("mit as? MutableIterable") { mit as? MutableIterable<*> }
safeAsReturnsNonNull("arrayList as? MutableIterable") { arrayList as? MutableIterable<*> }
val coll = C() as Any
val mcoll = MC()
safeAsReturnsNull("coll as? MutableIterable") { coll as? MutableIterable<*> }
safeAsReturnsNull("coll as? MutableCollection") { coll as? MutableCollection<*> }
safeAsReturnsNonNull("mcoll as? MutableIterable") { mcoll as? MutableIterable<*> }
safeAsReturnsNonNull("mcoll as? MutableCollection") { mcoll as? MutableCollection<*> }
safeAsReturnsNonNull("arrayList as? MutableCollection") { arrayList as? MutableCollection<*> }
val list = L() as Any
val mlist = ML()
safeAsReturnsNull("list as? MutableIterable") { list as? MutableIterable<*> }
safeAsReturnsNull("list as? MutableCollection") { list as? MutableCollection<*> }
safeAsReturnsNull("list as? MutableList") { list as? MutableList<*> }
safeAsReturnsNonNull("mlist as? MutableIterable") { mlist as? MutableIterable<*> }
safeAsReturnsNonNull("mlist as? MutableCollection") { mlist as? MutableCollection<*> }
safeAsReturnsNonNull("mlist as? MutableList") { mlist as? MutableList<*> }
val set = S() as Any
val mset = MS()
val hashSet = HashSet<String>()
safeAsReturnsNull("set as? MutableIterable") { set as? MutableIterable<*> }
safeAsReturnsNull("set as? MutableCollection") { set as? MutableCollection<*> }
safeAsReturnsNull("set as? MutableSet") { set as? MutableSet<*> }
safeAsReturnsNonNull("mset as? MutableIterable") { mset as? MutableIterable<*> }
safeAsReturnsNonNull("mset as? MutableCollection") { mset as? MutableCollection<*> }
safeAsReturnsNonNull("mset as? MutableSet") { mset as? MutableSet<*> }
safeAsReturnsNonNull("hashSet as? MutableSet") { hashSet as? MutableSet<*> }
val map = M() as Any
val mmap = MM()
val hashMap = HashMap<String, String>()
safeAsReturnsNull("map as? MutableMap") { map as? MutableMap<*, *> }
safeAsReturnsNonNull("mmap as? MutableMap") { mmap as? MutableMap<*, *> }
safeAsReturnsNonNull("hashMap as? MutableMap") { hashMap as? MutableMap<*, *> }
val entry = ME() as Any
val mentry = MME()
safeAsReturnsNull("entry as? MutableMap.MutableEntry") { entry as? MutableMap.MutableEntry<*, *> }
safeAsReturnsNonNull("mentry as? MutableMap.MutableEntry") { mentry as? MutableMap.MutableEntry<*, *> }
hashMap[""] = ""
val hashMapEntry = hashMap.entries.first()
safeAsReturnsNonNull("hashMapEntry as? MutableMap.MutableEntry") { hashMapEntry as? MutableMap.MutableEntry<*, *> }
safeAsReturnsNull("null as? MutableIterator") { null as? MutableIterator<*> }
safeAsReturnsNull("null as? MutableListIterator") { null as? MutableListIterator<*> }
safeAsReturnsNull("null as? MutableIterable") { null as? MutableIterable<*> }
safeAsReturnsNull("null as? MutableCollection") { null as? MutableCollection<*> }
safeAsReturnsNull("null as? MutableList") { null as? MutableList<*> }
safeAsReturnsNull("null as? MutableSet") { null as? MutableSet<*> }
safeAsReturnsNull("null as? MutableMap") { null as? MutableMap<*, *> }
safeAsReturnsNull("null as? MutableMap.MutableEntry") { null as? MutableMap.MutableEntry<*, *> }
safeAsReturnsNull("mlist as? MutableSet") { mlist as? MutableSet<*> }
safeAsReturnsNull("mlist as? MutableIterator") { mlist as? MutableIterator<*> }
return "OK"
}
@@ -0,0 +1,140 @@
// WITH_RUNTIME
fun unsupported(): Nothing = throw UnsupportedOperationException()
class Weird : Iterator<String>, MutableIterable<String>, MutableMap.MutableEntry<String, String> {
override fun next(): String = unsupported()
override fun hasNext(): Boolean = unsupported()
override val key: String get() = unsupported()
override val value: String get() = unsupported()
override fun setValue(value: String): String = unsupported()
override fun iterator(): MutableIterator<String> = unsupported()
}
inline fun asFailsWithCCE(operation: String, cast: () -> Unit) {
try {
cast()
}
catch (e: java.lang.ClassCastException) {
return
}
catch (e: Throwable) {
throw AssertionError("$operation: should throw ClassCastException, got $e")
}
throw AssertionError("$operation: should throw ClassCastException, no exception thrown")
}
inline fun asSucceeds(operation: String, cast: () -> Unit) {
try {
cast()
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
}
inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) {
try {
val x = cast()
assert(x == null) { "$operation: should return null, got $x" }
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
}
inline fun safeAsReturnsNonNull(operation: String, cast: () -> Any?) {
try {
val x = cast()
assert(x != null) { "$operation: should return non-null" }
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
}
inline fun <reified T> reifiedIs(x: Any): Boolean = x is T
inline fun <reified T> reifiedIsNot(x: Any): Boolean = x !is T
inline fun <reified T> reifiedAsSucceeds(x: Any, operation: String) {
try {
x as T
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
}
inline fun <reified T> reifiedAsFailsWithCCE(x: Any, operation: String) {
try {
x as T
}
catch (e: java.lang.ClassCastException) {
return
}
catch (e: Throwable) {
throw AssertionError("$operation: should throw ClassCastException, got $e")
}
throw AssertionError("$operation: should fail with CCE, no exception thrown")
}
inline fun <reified T> reifiedSafeAsReturnsNonNull(x: Any?, operation: String) {
val y = try {
x as? T
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
if (y == null) {
throw AssertionError("$operation: should return non-null, got null")
}
}
inline fun <reified T> reifiedSafeAsReturnsNull(x: Any?, operation: String) {
val y = try {
x as? T
}
catch (e: Throwable) {
throw AssertionError("$operation: should not throw exceptions, got $e")
}
if (y != null) {
throw AssertionError("$operation: should return null, got $y")
}
}
fun box(): String {
val w: Any = Weird()
assert(w is Iterator<*>) { "w is Iterator<*>" }
assert(w !is MutableIterator<*>) { "w !is MutableIterator<*>" }
assert(w is MutableIterable<*>) { "w is MutableIterable<*>" }
assert(w is MutableMap.MutableEntry<*, *>) { "w is MutableMap.MutableEntry<*, *>" }
asSucceeds("w as Iterator<*>") { w as Iterator<*> }
asFailsWithCCE("w as MutableIterator<*>") { w as MutableIterator<*> }
asSucceeds("w as MutableIterable<*>") { w as MutableIterable<*> }
asSucceeds("w as MutableMap.MutableEntry<*, *>") { w as MutableMap.MutableEntry<*, *> }
safeAsReturnsNonNull("w as Iterator<*>") { w as? Iterator<*> }
safeAsReturnsNull("w as? MutableIterator<*>") { w as? MutableIterator<*> }
safeAsReturnsNonNull("w as? MutableIterable<*>") { w as? MutableIterable<*> }
safeAsReturnsNonNull("w as? MutableMap.MutableEntry<*, *>") { w as? MutableMap.MutableEntry<*, *> }
assert(reifiedIs<Iterator<*>>(w)) { "reifiedIs<Iterator<*>>(w)" }
assert(reifiedIsNot<MutableIterator<*>>(w)) { "reifiedIsNot<MutableIterator<*>>(w)" }
assert(reifiedIs<MutableIterable<*>>(w)) { "reifiedIs<MutableIterable<*>>(w)" }
assert(reifiedIs<MutableMap.MutableEntry<*, *>>(w)) { "reifiedIs<MutableMap.MutableEntry<*, *>>(w)" }
reifiedAsSucceeds<Iterator<*>>(w, "reified w as Iterator<*>")
reifiedAsFailsWithCCE<MutableIterator<*>>(w, "reified w as MutableIterator<*>")
reifiedAsSucceeds<MutableIterable<*>>(w, "reified w as MutableIterable<*>")
reifiedAsSucceeds<MutableMap.MutableEntry<*, *>>(w, "reified w as MutableMap.MutableEntry<*, *>")
reifiedSafeAsReturnsNonNull<Iterator<*>>(w, "reified w as? Iterator<*>")
reifiedSafeAsReturnsNull<MutableIterator<*>>(w, "reified w as? MutableIterator<*>")
reifiedSafeAsReturnsNonNull<MutableIterable<*>>(w, "reified w as? MutableIterable<*>")
reifiedSafeAsReturnsNonNull<MutableMap.MutableEntry<*, *>>(w, "reified w as? MutableMap.MutableEntry<*, *>")
return "OK"
}