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
+23
View File
@@ -0,0 +1,23 @@
// WITH_RUNTIME
fun <T> test1() = null as T
fun <T> test2(): T {
val a : Any? = null
return a as T
}
fun <T: Any> test3() = null as T
fun box(): String {
if (test1<Int?>() != null) return "fail: test1"
if (test2<Int?>() != null) return "fail: test2"
var result3 = "fail"
try {
test3<Int>()
}
catch(e: TypeCastException) {
result3 = "OK"
}
if (result3 != "OK") return "fail: test3"
return "OK"
}
@@ -0,0 +1,251 @@
// WITH_RUNTIME
// This is a big, ugly, semi-auto generated test.
// Use corresponding 'Small' test for debug.
import kotlin.test.*
fun fn0() {}
fun fn1(x0: Any) {}
fun fn2(x0: Any, x1: Any) {}
fun fn3(x0: Any, x1: Any, x2: Any) {}
fun fn4(x0: Any, x1: Any, x2: Any, x3: Any) {}
fun fn5(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any) {}
fun fn6(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any) {}
fun fn7(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any) {}
fun fn8(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any) {}
fun fn9(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any) {}
fun fn10(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any) {}
fun fn11(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any) {}
fun fn12(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any) {}
fun fn13(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any) {}
fun fn14(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any) {}
fun fn15(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any) {}
fun fn16(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any) {}
fun fn17(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any) {}
fun fn18(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any) {}
fun fn19(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any) {}
fun fn20(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any) {}
fun fn21(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any, x20: Any) {}
fun fn22(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any, x20: Any, x21: Any) {}
val fns = arrayOf<Any>(::fn0, ::fn1, ::fn2, ::fn3, ::fn4, ::fn5, ::fn6, ::fn7, ::fn8, ::fn9,
::fn10, ::fn11, ::fn12, ::fn13, ::fn14, ::fn15, ::fn16, ::fn17, ::fn18, ::fn19,
::fn20, ::fn21, ::fn22)
inline fun asFailsWithCCE(operation: String, crossinline block: () -> Unit) {
assertFailsWith(ClassCastException::class, "$operation should throw an exception") {
block()
}
}
inline fun asSucceeds(operation: String, block: () -> Unit) {
block()
}
interface TestFnBase {
fun testGood(x: Any)
fun testBad(x: Any)
}
object TestFn0 : TestFnBase {
override fun testGood(x: Any) { x as Function0<*> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function0<*>") {
x as Function0<*>
}
}
object TestFn1 : TestFnBase {
override fun testGood(x: Any) { x as Function1<*, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function1<*, *>") {
x as Function1<*, *>
}
}
object TestFn2 : TestFnBase {
override fun testGood(x: Any) { x as Function2<*, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function2<*, *, *>") {
x as Function2<*, *, *>
}
}
object TestFn3 : TestFnBase {
override fun testGood(x: Any) { x as Function3<*, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function3<*, *, *, *>") {
x as Function3<*, *, *, *>
}
}
object TestFn4 : TestFnBase {
override fun testGood(x: Any) { x as Function4<*, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function4<*, *, *, *, *>") {
x as Function4<*, *, *, *, *>
}
}
object TestFn5 : TestFnBase {
override fun testGood(x: Any) { x as Function5<*, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function5<*, *, *, *, *, *>") {
x as Function5<*, *, *, *, *, *>
}
}
object TestFn6 : TestFnBase {
override fun testGood(x: Any) { x as Function6<*, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function6<*, *, *, *, *, *, *>") {
x as Function6<*, *, *, *, *, *, *>
}
}
object TestFn7 : TestFnBase {
override fun testGood(x: Any) { x as Function7<*, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function7<*, *, *, *, *, *, *, *>") {
x as Function7<*, *, *, *, *, *, *, *>
}
}
object TestFn8 : TestFnBase {
override fun testGood(x: Any) { x as Function8<*, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function8<*, *, *, *, *, *, *, *, *>") {
x as Function8<*, *, *, *, *, *, *, *, *>
}
}
object TestFn9 : TestFnBase {
override fun testGood(x: Any) { x as Function9<*, *, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function9<*, *, *, *, *, *, *, *, *, *>") {
x as Function9<*, *, *, *, *, *, *, *, *, *>
}
}
object TestFn10 : TestFnBase {
override fun testGood(x: Any) { x as Function10<*, *, *, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function10<*, *, *, *, *, *, *, *, *, *, *>") {
x as Function10<*, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn11 : TestFnBase {
override fun testGood(x: Any) { x as Function11<*, *, *, *, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function11<*, *, *, *, *, *, *, *, *, *, *, *>") {
x as Function11<*, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn12 : TestFnBase {
override fun testGood(x: Any) { x as Function12<*, *, *, *, *, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn13 : TestFnBase {
override fun testGood(x: Any) { x as Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn14 : TestFnBase {
override fun testGood(x: Any) { x as Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn15 : TestFnBase {
override fun testGood(x: Any) { x as Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn16 : TestFnBase {
override fun testGood(x: Any) { x as Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn17 : TestFnBase {
override fun testGood(x: Any) { x as Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn18 : TestFnBase {
override fun testGood(x: Any) { x as Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn19 : TestFnBase {
override fun testGood(x: Any) { x as Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn20 : TestFnBase {
override fun testGood(x: Any) { x as Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn21 : TestFnBase {
override fun testGood(x: Any) { x as Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn22 : TestFnBase {
override fun testGood(x: Any) { x as Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *> }
override fun testBad(x: Any) =
asFailsWithCCE("x as Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
val tests = arrayOf<TestFnBase>(TestFn0, TestFn1, TestFn2, TestFn3, TestFn4, TestFn5, TestFn6, TestFn7, TestFn8, TestFn9,
TestFn10, TestFn11, TestFn12, TestFn13, TestFn14, TestFn15, TestFn16, TestFn17, TestFn18, TestFn19,
TestFn20, TestFn21, TestFn22)
fun box(): String {
for (fnI in 0 .. 22) {
for (testI in 0 .. 22) {
if (fnI == testI) {
tests[testI].testGood(fns[fnI])
}
else {
tests[testI].testBad(fns[fnI])
}
}
}
return "OK"
}
@@ -0,0 +1,178 @@
// WITH_RUNTIME
// This is a big, ugly, semi-auto generated test.
// Use corresponding 'Small' test for debug.
fun fn0() {}
fun fn1(x0: Any) {}
fun fn2(x0: Any, x1: Any) {}
fun fn3(x0: Any, x1: Any, x2: Any) {}
fun fn4(x0: Any, x1: Any, x2: Any, x3: Any) {}
fun fn5(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any) {}
fun fn6(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any) {}
fun fn7(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any) {}
fun fn8(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any) {}
fun fn9(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any) {}
fun fn10(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any) {}
fun fn11(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any) {}
fun fn12(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any) {}
fun fn13(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any) {}
fun fn14(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any) {}
fun fn15(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any) {}
fun fn16(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any) {}
fun fn17(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any) {}
fun fn18(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any) {}
fun fn19(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any) {}
fun fn20(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any) {}
fun fn21(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any, x20: Any) {}
fun fn22(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any, x20: Any, x21: Any) {}
val fns = arrayOf<Any>(::fn0, ::fn1, ::fn2, ::fn3, ::fn4, ::fn5, ::fn6, ::fn7, ::fn8, ::fn9,
::fn10, ::fn11, ::fn12, ::fn13, ::fn14, ::fn15, ::fn16, ::fn17, ::fn18, ::fn19,
::fn20, ::fn21, ::fn22)
abstract class TestFnBase(val type: String) {
abstract fun testGood(x: Any)
abstract fun testBad(x: Any)
protected fun assertIs(x: Any, condition: Boolean) {
assert(condition) { "x is $type: failed for $x" }
}
protected fun assertIsNot(x: Any, condition: Boolean) {
assert(condition) { "x !is $type: failed for $x" }
}
}
object TestFn0 : TestFnBase("Function0<*>") {
override fun testGood(x: Any) { assertIs(x, x is Function0<*>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function0<*>) }
}
object TestFn1 : TestFnBase("Function1<*, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function1<*, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function1<*, *>) }
}
object TestFn2 : TestFnBase("Function2<*, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function2<*, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function2<*, *, *>) }
}
object TestFn3 : TestFnBase("Function3<*, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function3<*, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function3<*, *, *, *>) }
}
object TestFn4 : TestFnBase("Function4<*, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function4<*, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function4<*, *, *, *, *>) }
}
object TestFn5 : TestFnBase("Function5<*, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function5<*, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function5<*, *, *, *, *, *>) }
}
object TestFn6 : TestFnBase("Function6<*, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function6<*, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function6<*, *, *, *, *, *, *>) }
}
object TestFn7 : TestFnBase("Function7<*, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function7<*, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function7<*, *, *, *, *, *, *, *>) }
}
object TestFn8 : TestFnBase("Function8<*, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function8<*, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function8<*, *, *, *, *, *, *, *, *>) }
}
object TestFn9 : TestFnBase("Function9<*, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function9<*, *, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function9<*, *, *, *, *, *, *, *, *, *>) }
}
object TestFn10 : TestFnBase("Function10<*, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function10<*, *, *, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function10<*, *, *, *, *, *, *, *, *, *, *>) }
}
object TestFn11 : TestFnBase("Function11<*, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function11<*, *, *, *, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function11<*, *, *, *, *, *, *, *, *, *, *, *>) }
}
object TestFn12 : TestFnBase("Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>) }
}
object TestFn13 : TestFnBase("Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
}
object TestFn14 : TestFnBase("Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
}
object TestFn15 : TestFnBase("Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
}
object TestFn16 : TestFnBase("Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
}
object TestFn17 : TestFnBase("Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
}
object TestFn18 : TestFnBase("Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
}
object TestFn19 : TestFnBase("Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
}
object TestFn20 : TestFnBase("Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
}
object TestFn21 : TestFnBase("Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
}
object TestFn22 : TestFnBase("Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertIs(x, x is Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
override fun testBad(x: Any) { assertIsNot(x, x !is Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>) }
}
val tests = arrayOf<TestFnBase>(TestFn0, TestFn1, TestFn2, TestFn3, TestFn4, TestFn5, TestFn6, TestFn7, TestFn8, TestFn9,
TestFn10, TestFn11, TestFn12, TestFn13, TestFn14, TestFn15, TestFn16, TestFn17, TestFn18, TestFn19,
TestFn20, TestFn21, TestFn22)
fun box(): String {
for (fnI in 0 .. 22) {
for (testI in 0 .. 22) {
if (fnI == testI) {
tests[testI].testGood(fns[fnI])
}
else {
tests[testI].testBad(fns[fnI])
}
}
}
return "OK"
}
@@ -0,0 +1,57 @@
// WITH_REFLECT
fun fn0() {}
fun fn1(x: Any) {}
val lambda0 = {} as () -> Unit
val lambda1 = { x: Any -> } as (Any) -> Unit
fun Any.extFun() {}
var Any.extProp: String
get() = "extProp"
set(x: String) {}
class A {
fun foo() {}
}
fun box(): String {
val f0 = ::fn0 as Any
val f1 = ::fn1 as Any
val ef = Any::extFun as Any
val epg = Any::extProp.getter
val eps = Any::extProp.setter
val afoo = A::foo
fun local0() {}
fun local1(x: Any) {}
val localFun0 = ::local0 as Any
val localFun1 = ::local1 as Any
assert(f0 is Function0<*>) { "Failed: f0 is Function0<*>" }
assert(f1 is Function1<*, *>) { "Failed: f1 is Function1<*, *>" }
assert(f0 !is Function1<*, *>) { "Failed: f0 !is Function1<*, *>" }
assert(f1 !is Function0<*>) { "Failed: f1 !is Function0<*>" }
assert(lambda0 is Function0<*>) { "Failed: lambda0 is Function0<*>" }
assert(lambda1 is Function1<*, *>) { "Failed: lambda1 is Function1<*, *>" }
assert(lambda0 !is Function1<*, *>) { "Failed: lambda0 !is Function1<*, *>" }
assert(lambda1 !is Function0<*>) { "Failed: lambda1 !is Function0<*>" }
assert(localFun0 is Function0<*>) { "Failed: localFun0 is Function0<*>" }
assert(localFun1 is Function1<*, *>) { "Failed: localFun1 is Function1<*, *>" }
assert(localFun0 !is Function1<*, *>) { "Failed: localFun0 !is Function1<*, *>" }
assert(localFun1 !is Function0<*>) { "Failed: localFun1 !is Function0<*>" }
assert(ef is Function1<*, *>) { "Failed: ef is Function1<*, *>" }
assert(epg is Function1<*, *>) { "Failed: epg is Function1<*, *>"}
assert(eps is Function2<*, *, *>) { "Failed: eps is Function2<*, *, *>"}
assert(afoo is Function1<*, *>) { "afoo is Function1<*, *>" }
return "OK"
}
@@ -0,0 +1,274 @@
// WITH_RUNTIME
// This is a big, ugly, semi-auto generated test.
// Use corresponding 'Small' test for debug.
import kotlin.test.*
fun fn0() {}
fun fn1(x0: Any) {}
fun fn2(x0: Any, x1: Any) {}
fun fn3(x0: Any, x1: Any, x2: Any) {}
fun fn4(x0: Any, x1: Any, x2: Any, x3: Any) {}
fun fn5(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any) {}
fun fn6(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any) {}
fun fn7(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any) {}
fun fn8(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any) {}
fun fn9(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any) {}
fun fn10(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any) {}
fun fn11(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any) {}
fun fn12(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any) {}
fun fn13(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any) {}
fun fn14(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any) {}
fun fn15(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any) {}
fun fn16(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any) {}
fun fn17(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any) {}
fun fn18(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any) {}
fun fn19(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any) {}
fun fn20(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any) {}
fun fn21(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any, x20: Any) {}
fun fn22(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any, x20: Any, x21: Any) {}
val fns = arrayOf<Any>(::fn0, ::fn1, ::fn2, ::fn3, ::fn4, ::fn5, ::fn6, ::fn7, ::fn8, ::fn9,
::fn10, ::fn11, ::fn12, ::fn13, ::fn14, ::fn15, ::fn16, ::fn17, ::fn18, ::fn19,
::fn20, ::fn21, ::fn22)
inline fun <reified T> reifiedAsSucceeds(x: Any, operation: String) {
x as T
}
inline fun <reified T> reifiedAsFailsWithCCE(x: Any, operation: String) {
assertFailsWith(ClassCastException::class, "$operation should throw an exception") {
x as T
}
}
interface TestFnBase {
fun testGood(x: Any)
fun testBad(x: Any)
}
object TestFn0 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function0<*>>(
x, "x as Function0<*>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function0<*>>(
x, "x as Function0<*>")
}
object TestFn1 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function1<*, *>>(
x, "x as Function1<*, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function1<*, *>>(
x, "x as Function1<*, *>")
}
object TestFn2 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function2<*, *, *>>(
x, "x as Function2<*, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function2<*, *, *>>(
x, "x as Function2<*, *, *>")
}
object TestFn3 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function3<*, *, *, *>>(
x, "x as Function3<*, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function3<*, *, *, *>>(
x, "x as Function3<*, *, *, *>")
}
object TestFn4 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function4<*, *, *, *, *>>(
x, "x as Function4<*, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function4<*, *, *, *, *>>(
x, "x as Function4<*, *, *, *, *>")
}
object TestFn5 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function5<*, *, *, *, *, *>>(
x, "x as Function5<*, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function5<*, *, *, *, *, *>>(
x, "x as Function5<*, *, *, *, *, *>")
}
object TestFn6 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function6<*, *, *, *, *, *, *>>(
x, "x as Function6<*, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function6<*, *, *, *, *, *, *>>(
x, "x as Function6<*, *, *, *, *, *, *>")
}
object TestFn7 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function7<*, *, *, *, *, *, *, *>>(
x, "x as Function7<*, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function7<*, *, *, *, *, *, *, *>>(
x, "x as Function7<*, *, *, *, *, *, *, *>")
}
object TestFn8 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function8<*, *, *, *, *, *, *, *, *>>(
x, "x as Function8<*, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function8<*, *, *, *, *, *, *, *, *>>(
x, "x as Function8<*, *, *, *, *, *, *, *, *>")
}
object TestFn9 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function9<*, *, *, *, *, *, *, *, *, *>>(
x, "x as Function9<*, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function9<*, *, *, *, *, *, *, *, *, *>>(
x, "x as Function9<*, *, *, *, *, *, *, *, *, *>")
}
object TestFn10 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function10<*, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function10<*, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function10<*, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function10<*, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn11 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function11<*, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function11<*, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function11<*, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function11<*, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn12 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn13 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn14 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn15 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn16 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn17 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn18 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn19 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn20 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn21 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
object TestFn22 : TestFnBase {
override fun testGood(x: Any) =
reifiedAsSucceeds<Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
override fun testBad(x: Any) =
reifiedAsFailsWithCCE<Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(
x, "x as Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>")
}
val tests = arrayOf<TestFnBase>(TestFn0, TestFn1, TestFn2, TestFn3, TestFn4, TestFn5, TestFn6, TestFn7, TestFn8, TestFn9,
TestFn10, TestFn11, TestFn12, TestFn13, TestFn14, TestFn15, TestFn16, TestFn17, TestFn18, TestFn19,
TestFn20, TestFn21, TestFn22)
fun box(): String {
for (fnI in 0 .. 22) {
for (testI in 0 .. 22) {
if (fnI == testI) {
tests[testI].testGood(fns[fnI])
}
else {
tests[testI].testBad(fns[fnI])
}
}
}
return "OK"
}
@@ -0,0 +1,192 @@
// WITH_RUNTIME
// This is a big, ugly, semi-auto generated test.
// Use corresponding 'Small' test for debug.
fun fn0() {}
fun fn1(x0: Any) {}
fun fn2(x0: Any, x1: Any) {}
fun fn3(x0: Any, x1: Any, x2: Any) {}
fun fn4(x0: Any, x1: Any, x2: Any, x3: Any) {}
fun fn5(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any) {}
fun fn6(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any) {}
fun fn7(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any) {}
fun fn8(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any) {}
fun fn9(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any) {}
fun fn10(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any) {}
fun fn11(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any) {}
fun fn12(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any) {}
fun fn13(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any) {}
fun fn14(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any) {}
fun fn15(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any) {}
fun fn16(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any) {}
fun fn17(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any) {}
fun fn18(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any) {}
fun fn19(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any) {}
fun fn20(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any) {}
fun fn21(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any, x20: Any) {}
fun fn22(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any, x20: Any, x21: Any) {}
val fns = arrayOf<Any>(::fn0, ::fn1, ::fn2, ::fn3, ::fn4, ::fn5, ::fn6, ::fn7, ::fn8, ::fn9,
::fn10, ::fn11, ::fn12, ::fn13, ::fn14, ::fn15, ::fn16, ::fn17, ::fn18, ::fn19,
::fn20, ::fn21, ::fn22)
inline fun <reified T> assertReifiedIs(x: Any, type: String) {
val answer: Boolean
try {
answer = x is T
}
catch (e: Throwable) {
throw AssertionError("$x is $type: should not throw exceptions, got $e")
}
assert(answer) { "$x is $type: failed" }
}
inline fun <reified T> assertReifiedIsNot(x: Any, type: String) {
val answer: Boolean
try {
answer = x !is T
}
catch (e: Throwable) {
throw AssertionError("$x !is $type: should not throw exceptions, got $e")
}
assert(answer) { "$x !is $type: failed" }
}
abstract class TestFnBase(val type: String) {
abstract fun testGood(x: Any)
abstract fun testBad(x: Any)
}
object TestFn0 : TestFnBase("Function0<*>") {
override fun testGood(x: Any) { assertReifiedIs<Function0<*>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function0<*>>(x, type) }
}
object TestFn1 : TestFnBase("Function1<*, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function1<*, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function1<*, *>>(x, type) }
}
object TestFn2 : TestFnBase("Function2<*, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function2<*, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function2<*, *, *>>(x, type) }
}
object TestFn3 : TestFnBase("Function3<*, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function3<*, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function3<*, *, *, *>>(x, type) }
}
object TestFn4 : TestFnBase("Function4<*, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function4<*, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function4<*, *, *, *, *>>(x, type) }
}
object TestFn5 : TestFnBase("Function5<*, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function5<*, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function5<*, *, *, *, *, *>>(x, type) }
}
object TestFn6 : TestFnBase("Function6<*, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function6<*, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function6<*, *, *, *, *, *, *>>(x, type) }
}
object TestFn7 : TestFnBase("Function7<*, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function7<*, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function7<*, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn8 : TestFnBase("Function8<*, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function8<*, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function8<*, *, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn9 : TestFnBase("Function9<*, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function9<*, *, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function9<*, *, *, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn10 : TestFnBase("Function10<*, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function10<*, *, *, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function10<*, *, *, *, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn11 : TestFnBase("Function11<*, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function11<*, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function11<*, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn12 : TestFnBase("Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn13 : TestFnBase("Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn14 : TestFnBase("Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn15 : TestFnBase("Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn16 : TestFnBase("Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn17 : TestFnBase("Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn18 : TestFnBase("Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn19 : TestFnBase("Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn20 : TestFnBase("Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn21 : TestFnBase("Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
}
object TestFn22 : TestFnBase("Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
override fun testGood(x: Any) { assertReifiedIs<Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
override fun testBad(x: Any) { assertReifiedIsNot<Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>>(x, type) }
}
val tests = arrayOf<TestFnBase>(TestFn0, TestFn1, TestFn2, TestFn3, TestFn4, TestFn5, TestFn6, TestFn7, TestFn8, TestFn9,
TestFn10, TestFn11, TestFn12, TestFn13, TestFn14, TestFn15, TestFn16, TestFn17, TestFn18, TestFn19,
TestFn20, TestFn21, TestFn22)
fun box(): String {
for (fnI in 0 .. 22) {
for (testI in 0 .. 22) {
if (fnI == testI) {
tests[testI].testGood(fns[fnI])
}
else {
tests[testI].testBad(fns[fnI])
}
}
}
return "OK"
}
@@ -0,0 +1,38 @@
// WITH_RUNTIME
fun fn0() {}
fun fn1(x: Any) {}
inline fun <reified T> assertReifiedIs(x: Any, type: String) {
val answer: Boolean
try {
answer = x is T
}
catch (e: Throwable) {
throw AssertionError("$x is $type: should not throw exceptions, got $e")
}
assert(answer) { "$x is $type: failed" }
}
inline fun <reified T> assertReifiedIsNot(x: Any, type: String) {
val answer: Boolean
try {
answer = x !is T
}
catch (e: Throwable) {
throw AssertionError("$x !is $type: should not throw exceptions, got $e")
}
assert(answer) { "$x !is $type: failed" }
}
fun box(): String {
val f0 = ::fn0 as Any
val f1 = ::fn1 as Any
assertReifiedIs<Function0<*>>(f0, "Function0<*>")
assertReifiedIs<Function1<*, *>>(f1, "Function1<*, *>")
assertReifiedIsNot<Function0<*>>(f1, "Function0<*>")
assertReifiedIsNot<Function1<*, *>>(f0, "Function1<*, *>")
return "OK"
}
@@ -0,0 +1,328 @@
// WITH_RUNTIME
// This is a big, ugly, semi-auto generated test.
// Use corresponding 'Small' test for debug.
fun fn0() {}
fun fn1(x0: Any) {}
fun fn2(x0: Any, x1: Any) {}
fun fn3(x0: Any, x1: Any, x2: Any) {}
fun fn4(x0: Any, x1: Any, x2: Any, x3: Any) {}
fun fn5(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any) {}
fun fn6(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any) {}
fun fn7(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any) {}
fun fn8(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any) {}
fun fn9(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any) {}
fun fn10(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any) {}
fun fn11(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any) {}
fun fn12(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any) {}
fun fn13(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any) {}
fun fn14(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any) {}
fun fn15(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any) {}
fun fn16(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any) {}
fun fn17(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any) {}
fun fn18(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any) {}
fun fn19(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any) {}
fun fn20(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any) {}
fun fn21(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any, x20: Any) {}
fun fn22(x0: Any, x1: Any, x2: Any, x3: Any, x4: Any, x5: Any, x6: Any, x7: Any, x8: Any, x9: Any, x10: Any, x11: Any, x12: Any, x13: Any, x14: Any, x15: Any, x16: Any, x17: Any, x18: Any, x19: Any, x20: Any, x21: Any) {}
val fns = arrayOf<Any>(::fn0, ::fn1, ::fn2, ::fn3, ::fn4, ::fn5, ::fn6, ::fn7, ::fn8, ::fn9,
::fn10, ::fn11, ::fn12, ::fn13, ::fn14, ::fn15, ::fn16, ::fn17, ::fn18, ::fn19,
::fn20, ::fn21, ::fn22)
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")
}
}
interface TestFnBase {
abstract fun testGood(x: Any)
abstract fun testBad(x: Any)
}
object TestFn0 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function0<*>") {
x as? Function0<*>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function0<*>") {
x as? Function0<*>
}
}
object TestFn1 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function1<*, *>") {
x as? Function1<*, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function1<*, *>") {
x as? Function1<*, *>
}
}
object TestFn2 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function2<*, *, *>") {
x as? Function2<*, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function2<*, *, *>") {
x as? Function2<*, *, *>
}
}
object TestFn3 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function3<*, *, *, *>") {
x as? Function3<*, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function3<*, *, *, *>") {
x as? Function3<*, *, *, *>
}
}
object TestFn4 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function4<*, *, *, *, *>") {
x as? Function4<*, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function4<*, *, *, *, *>") {
x as? Function4<*, *, *, *, *>
}
}
object TestFn5 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function5<*, *, *, *, *, *>") {
x as? Function5<*, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function5<*, *, *, *, *, *>") {
x as? Function5<*, *, *, *, *, *>
}
}
object TestFn6 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function6<*, *, *, *, *, *, *>") {
x as? Function6<*, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function6<*, *, *, *, *, *, *>") {
x as? Function6<*, *, *, *, *, *, *>
}
}
object TestFn7 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function7<*, *, *, *, *, *, *, *>") {
x as? Function7<*, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function7<*, *, *, *, *, *, *, *>") {
x as? Function7<*, *, *, *, *, *, *, *>
}
}
object TestFn8 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function8<*, *, *, *, *, *, *, *, *>") {
x as? Function8<*, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function8<*, *, *, *, *, *, *, *, *>") {
x as? Function8<*, *, *, *, *, *, *, *, *>
}
}
object TestFn9 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function9<*, *, *, *, *, *, *, *, *, *>") {
x as? Function9<*, *, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function9<*, *, *, *, *, *, *, *, *, *>") {
x as? Function9<*, *, *, *, *, *, *, *, *, *>
}
}
object TestFn10 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function10<*, *, *, *, *, *, *, *, *, *, *>") {
x as? Function10<*, *, *, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function10<*, *, *, *, *, *, *, *, *, *, *>") {
x as? Function10<*, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn11 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function11<*, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function11<*, *, *, *, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function11<*, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function11<*, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn12 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function12<*, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn13 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function13<*, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn14 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function14<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn15 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function15<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn16 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function16<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn17 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function17<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn18 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function18<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn19 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function19<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn20 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function20<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn21 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function21<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
object TestFn22 : TestFnBase {
override fun testGood(x: Any) =
safeAsReturnsNonNull("x as? Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
override fun testBad(x: Any) =
safeAsReturnsNull("x as? Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>") {
x as? Function22<*, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *, *>
}
}
val tests = arrayOf<TestFnBase>(TestFn0, TestFn1, TestFn2, TestFn3, TestFn4, TestFn5, TestFn6, TestFn7, TestFn8, TestFn9,
TestFn10, TestFn11, TestFn12, TestFn13, TestFn14, TestFn15, TestFn16, TestFn17, TestFn18, TestFn19,
TestFn20, TestFn21, TestFn22)
fun box(): String {
for (fnI in 0 .. 22) {
for (testI in 0 .. 22) {
if (fnI == testI) {
tests[testI].testGood(fns[fnI])
}
else {
tests[testI].testBad(fns[fnI])
}
}
}
return "OK"
}
@@ -0,0 +1,36 @@
// WITH_RUNTIME
fun fn0() {}
fun fn1(x: Any) {}
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 f0 = ::fn0 as Any
val f1 = ::fn1 as Any
safeAsReturnsNonNull("f0 as? Function0<*>") { f0 as? Function0<*> }
safeAsReturnsNull("f0 as? Function1<*, *>") { f0 as? Function1<*, *> }
safeAsReturnsNull("f1 as? Function0<*>") { f1 as? Function0<*> }
safeAsReturnsNonNull("f1 as? Function1<*, *>") { f1 as? Function1<*, *> }
return "OK"
}
@@ -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"
}
+17
View File
@@ -0,0 +1,17 @@
// WITH_RUNTIME
fun foo() {}
fun box(): String {
try {
foo() as Int?
}
catch (e: ClassCastException) {
return "OK"
}
catch (e: Throwable) {
return "Fail: ClassCastException should have been thrown, but was instead ${e.javaClass.getName()}: ${e.message}"
}
return "Fail: no exception was thrown"
}