Merge boxWithStdlib testData into box, delete BoxWithStdlib test
This commit is contained in:
committed by
Alexander Udalov
parent
22bfc9786a
commit
06a67e6602
@@ -0,0 +1,32 @@
|
||||
// WITH_RUNTIME
|
||||
// KT-5665
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class First
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Second(val value: String)
|
||||
|
||||
enum class E {
|
||||
@First
|
||||
E1 {
|
||||
fun foo() = "something"
|
||||
},
|
||||
|
||||
@Second("OK")
|
||||
E2
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val e = E::class.java
|
||||
|
||||
val e1 = e.getDeclaredField(E.E1.toString()).getAnnotations()
|
||||
if (e1.size != 1) return "Fail E1 size: ${e1.toList()}"
|
||||
if (e1[0].annotationClass.java != First::class.java) return "Fail E1: ${e1.toList()}"
|
||||
|
||||
val e2 = e.getDeclaredField(E.E2.toString()).getAnnotations()
|
||||
if (e2.size != 1) return "Fail E2 size: ${e2.toList()}"
|
||||
if (e2[0].annotationClass.java != Second::class.java) return "Fail E2: ${e2.toList()}"
|
||||
|
||||
return (e2[0] as Second).value
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import java.lang.reflect.Method
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(val x: String)
|
||||
|
||||
fun foo0(block: () -> Unit) = block.javaClass
|
||||
fun foo1(block: (String) -> Unit) = block.javaClass
|
||||
|
||||
fun testMethod(method: Method, name: String) {
|
||||
assertEquals("OK", method.getAnnotation(Ann::class.java).x, "On method of test named `$name`")
|
||||
|
||||
for ((index, annotations) in method.getParameterAnnotations().withIndex()) {
|
||||
val ann = annotations.filterIsInstance<Ann>().single()
|
||||
assertEquals("OK$index", ann.x, "On parameter $index of test named `$name`")
|
||||
}
|
||||
}
|
||||
|
||||
fun testClass(clazz: Class<*>, name: String) {
|
||||
val invokes = clazz.getDeclaredMethods().single() { !it.isBridge() }
|
||||
testMethod(invokes, name)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testClass(foo0( @Ann("OK") fun() {} ), "1")
|
||||
testClass(foo1( @Ann("OK") fun(@Ann("OK0") x: String) {} ), "2")
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import java.lang.reflect.Method
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(val x: String)
|
||||
|
||||
fun foo0(block: () -> Unit) = block.javaClass
|
||||
|
||||
fun testMethod(method: Method, name: String) {
|
||||
assertEquals("OK", method.getAnnotation(Ann::class.java).x, "On method of test named `$name`")
|
||||
|
||||
for ((index, annotations) in method.getParameterAnnotations().withIndex()) {
|
||||
val ann = annotations.filterIsInstance<Ann>().single()
|
||||
assertEquals("OK$index", ann.x, "On parameter $index of test named `$name`")
|
||||
}
|
||||
}
|
||||
|
||||
fun testClass(clazz: Class<*>, name: String) {
|
||||
val invokes = clazz.getDeclaredMethods().single() { !it.isBridge() }
|
||||
testMethod(invokes, name)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
testClass(foo0(@Ann("OK") { }), "1")
|
||||
testClass(foo0( @Ann("OK") { }), "2")
|
||||
|
||||
testClass(foo0() @Ann("OK") { }, "3")
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
annotation class Ann(val v: String = "???")
|
||||
@Ann open class My
|
||||
fun box(): String {
|
||||
val v = @Ann("OK") object: My() {}
|
||||
val klass = v.javaClass
|
||||
|
||||
val annotations = klass.annotations.toList()
|
||||
// Ann, kotlin.Metadata
|
||||
if (annotations.size != 2) return "Fail annotations size is ${annotations.size}: $annotations"
|
||||
val annotation = annotations.filterIsInstance<Ann>().firstOrNull()
|
||||
?: return "Fail no @Ann: $annotations"
|
||||
|
||||
return annotation.v
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(val x: Int)
|
||||
class A {
|
||||
@Ann(1) fun foo(x: Int, y: Int = 2, z: Int) {}
|
||||
|
||||
@Ann(1) constructor(x: Int, y: Int = 2, z: Int)
|
||||
}
|
||||
|
||||
class B @Ann(1) constructor(x: Int, y: Int = 2, z: Int) {}
|
||||
|
||||
fun test(name: String, annotations: Array<out Annotation>) {
|
||||
assertEquals(1, annotations.filterIsInstance<Ann>().single().x, "$name[0]")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val foo = A::class.java.getDeclaredMethods().first { it.getName() == "foo" }
|
||||
test("foo", foo.getDeclaredAnnotations())
|
||||
|
||||
val fooDefault = A::class.java.getDeclaredMethods().first { it.getName() == "foo\$default" }
|
||||
test("foo", foo.getDeclaredAnnotations())
|
||||
|
||||
val (secondary, secondaryDefault) = A::class.java.getDeclaredConstructors().partition { it.getParameterTypes().size == 3 }
|
||||
|
||||
test("secondary", secondary[0].getDeclaredAnnotations())
|
||||
test("secondary\$default", secondaryDefault[0].getDeclaredAnnotations())
|
||||
|
||||
val (primary, primaryDefault) = B::class.java.getConstructors().partition { it.getParameterTypes().size == 3 }
|
||||
|
||||
test("primary", primary[0].getDeclaredAnnotations())
|
||||
test("primary\$default", primaryDefault[0].getDeclaredAnnotations())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val i: Int = 1,
|
||||
val s: String = "a",
|
||||
val a: Ann2 = Ann2(),
|
||||
val e: MyEnum = MyEnum.A,
|
||||
val c: KClass<*> = A::class,
|
||||
val ia: IntArray = intArrayOf(1, 2),
|
||||
val sa: Array<String> = arrayOf("a", "b")
|
||||
)
|
||||
|
||||
fun box(): String {
|
||||
val ann = MyClass::class.java.getAnnotation(Ann::class.java)
|
||||
if (ann == null) return "fail: cannot find Ann on MyClass}"
|
||||
if (ann.i != 1) return "fail: annotation parameter i should be 1, but was ${ann.i}"
|
||||
if (ann.s != "a") return "fail: annotation parameter s should be \"a\", but was ${ann.s}"
|
||||
val annSimpleName = ann.a.annotationClass.java.getSimpleName()
|
||||
if (annSimpleName != "Ann2") return "fail: annotation parameter a should be of class Ann2, but was $annSimpleName"
|
||||
if (ann.e != MyEnum.A) return "fail: annotation parameter e should be MyEnum.A, but was ${ann.e}"
|
||||
if (ann.c.java != A::class.java) return "fail: annotation parameter c should be of class A, but was ${ann.c}"
|
||||
if (ann.ia[0] != 1 || ann.ia[1] != 2) return "fail: annotation parameter ia should be [1, 2], but was ${ann.ia}"
|
||||
if (ann.sa[0] != "a" || ann.sa[1] != "b") return "fail: annotation parameter ia should be [\"a\", \"b\"], but was ${ann.sa}"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
annotation class Ann2
|
||||
|
||||
enum class MyEnum {
|
||||
A
|
||||
}
|
||||
|
||||
class A
|
||||
|
||||
@Ann class MyClass
|
||||
@@ -0,0 +1,29 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class First
|
||||
|
||||
class MyClass() {
|
||||
public var x: String by Delegate()
|
||||
@First set
|
||||
}
|
||||
|
||||
class Delegate {
|
||||
operator fun getValue(t: Any?, p: KProperty<*>): String {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
operator fun setValue(t: Any?, p: KProperty<*>, i: String) {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val e = MyClass::class.java
|
||||
|
||||
val e1 = e.getDeclaredMethod("setX", String::class.java).getAnnotations()
|
||||
if (e1.size != 1) return "Fail E1 size: ${e1.toList()}"
|
||||
if (e1[0].annotationClass.java != First::class.java) return "Fail: ${e1.toList()}"
|
||||
|
||||
return MyClass().x
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@file:StringHolder("OK")
|
||||
@file:JvmName("FileClass")
|
||||
|
||||
@Target(AnnotationTarget.FILE)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
public annotation class StringHolder(val value: String)
|
||||
|
||||
fun box(): String =
|
||||
Class.forName("FileClass").getAnnotation(StringHolder::class.java)?.value ?: "null"
|
||||
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
|
||||
import java.lang.reflect.Modifier
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class CustomDelegate {
|
||||
operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name
|
||||
}
|
||||
|
||||
class C {
|
||||
@Volatile var vol = 1
|
||||
@Transient val tra = 1
|
||||
@delegate:Transient val del: String by CustomDelegate()
|
||||
|
||||
@Strictfp fun str() {}
|
||||
@Synchronized fun sync() {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C::class.java
|
||||
|
||||
if (c.getDeclaredField("vol").getModifiers() and Modifier.VOLATILE == 0) return "Fail: volatile"
|
||||
if (c.getDeclaredField("tra").getModifiers() and Modifier.TRANSIENT == 0) return "Fail: transient"
|
||||
if (c.getDeclaredField("del\$delegate").getModifiers() and Modifier.TRANSIENT == 0) return "Fail: delegate transient"
|
||||
|
||||
if (c.getDeclaredMethod("str").getModifiers() and Modifier.STRICT == 0) return "Fail: strict"
|
||||
if (c.getDeclaredMethod("sync").getModifiers() and Modifier.SYNCHRONIZED == 0) return "Fail: synchronized"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Ann(Foo.i, Foo.s, Foo.f, Foo.d, Foo.l, Foo.b, Foo.bool, Foo.c, Foo.str) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val ann = MyClass::class.java.getAnnotation(Ann::class.java)
|
||||
if (ann == null) return "fail: cannot find Ann on MyClass}"
|
||||
if (ann.i != 2) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||
if (ann.s != 2.toShort()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||
if (ann.f != 2.toFloat()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||
if (ann.d != 2.toDouble()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||
if (ann.l != 2.toLong()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||
if (ann.b != 2.toByte()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||
if (!ann.bool) return "fail: annotation parameter i should be true, but was ${ann.i}"
|
||||
if (ann.c != 'c') return "fail: annotation parameter i should be c, but was ${ann.i}"
|
||||
if (ann.str != "str") return "fail: annotation parameter i should be str, but was ${ann.i}"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val i: Int,
|
||||
val s: Short,
|
||||
val f: Float,
|
||||
val d: Double,
|
||||
val l: Long,
|
||||
val b: Byte,
|
||||
val bool: Boolean,
|
||||
val c: Char,
|
||||
val str: String
|
||||
)
|
||||
|
||||
class Foo {
|
||||
companion object {
|
||||
const val i: Int = 2
|
||||
const val s: Short = 2
|
||||
const val f: Float = 2.0.toFloat()
|
||||
const val d: Double = 2.0
|
||||
const val l: Long = 2
|
||||
const val b: Byte = 2
|
||||
const val bool: Boolean = true
|
||||
const val c: Char = 'c'
|
||||
const val str: String = "str"
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Ann(i, s, f, d, l, b, bool, c, str) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val ann = MyClass::class.java.getAnnotation(Ann::class.java)
|
||||
if (ann == null) return "fail: cannot find Ann on MyClass}"
|
||||
if (ann.i != 2) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||
if (ann.s != 2.toShort()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||
if (ann.f != 2.toFloat()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||
if (ann.d != 2.toDouble()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||
if (ann.l != 2.toLong()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||
if (ann.b != 2.toByte()) return "fail: annotation parameter i should be 2, but was ${ann.i}"
|
||||
if (!ann.bool) return "fail: annotation parameter i should be true, but was ${ann.i}"
|
||||
if (ann.c != 'c') return "fail: annotation parameter i should be c, but was ${ann.i}"
|
||||
if (ann.str != "str") return "fail: annotation parameter i should be str, but was ${ann.i}"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val i: Int,
|
||||
val s: Short,
|
||||
val f: Float,
|
||||
val d: Double,
|
||||
val l: Long,
|
||||
val b: Byte,
|
||||
val bool: Boolean,
|
||||
val c: Char,
|
||||
val str: String
|
||||
)
|
||||
|
||||
const val i: Int = 2
|
||||
const val s: Short = 2
|
||||
const val f: Float = 2.0.toFloat()
|
||||
const val d: Double = 2.0
|
||||
const val l: Long = 2
|
||||
const val b: Byte = 2
|
||||
const val bool: Boolean = true
|
||||
const val c: Char = 'c'
|
||||
const val str: String = "str"
|
||||
@@ -0,0 +1,21 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
annotation class A
|
||||
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class B(val items: Array<A> = arrayOf(A()))
|
||||
|
||||
@B
|
||||
class C
|
||||
|
||||
fun box(): String {
|
||||
val bClass = B::class.java
|
||||
val cClass = C::class.java
|
||||
|
||||
val items = cClass.getAnnotation(bClass).items
|
||||
assert(items.size == 1) { "Expected: [A()], got ${items.asList()}" }
|
||||
assert(items[0] is A) { "Expected: [A()], got ${items.asList()}" }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Ann(A.B.i) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val ann = MyClass::class.java.getAnnotation(Ann::class.java)
|
||||
if (ann == null) return "fail: cannot find Ann on MyClass}"
|
||||
if (ann.i != 1) return "fail: annotation parameter i should be 1, but was ${ann.i}"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(val i: Int)
|
||||
|
||||
class A {
|
||||
class B {
|
||||
companion object {
|
||||
const val i = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val b: Byte,
|
||||
val s: Short,
|
||||
val i: Int,
|
||||
val f: Float,
|
||||
val d: Double,
|
||||
val l: Long,
|
||||
val c: Char,
|
||||
val bool: Boolean
|
||||
)
|
||||
|
||||
fun box(): String {
|
||||
val ann = MyClass::class.java.getAnnotation(Ann::class.java)
|
||||
if (ann == null) return "fail: cannot find Ann on MyClass}"
|
||||
if (ann.b != 1.toByte()) return "fail: annotation parameter b should be 1, but was ${ann.b}"
|
||||
if (ann.s != 1.toShort()) return "fail: annotation parameter s should be 1, but was ${ann.s}"
|
||||
if (ann.i != 1) return "fail: annotation parameter i should be 1, but was ${ann.i}"
|
||||
if (ann.f != 1.toFloat()) return "fail: annotation parameter f should be 1, but was ${ann.f}"
|
||||
if (ann.d != 1.0) return "fail: annotation parameter d should be 1, but was ${ann.d}"
|
||||
if (ann.l != 1.toLong()) return "fail: annotation parameter l should be 1, but was ${ann.l}"
|
||||
if (ann.c != 'c') return "fail: annotation parameter c should be 1, but was ${ann.c}"
|
||||
if (!ann.bool) return "fail: annotation parameter bool should be 1, but was ${ann.bool}"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@Ann(1, 1, 1, 1.0.toFloat(), 1.0, 1, 'c', true) class MyClass
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Ann(i) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val ann = MyClass::class.java.getAnnotation(Ann::class.java)
|
||||
if (ann == null) return "fail: cannot find Ann on MyClass}"
|
||||
if (ann.i != 1) return "fail: annotation parameter i should be 1, but was ${ann.i}"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(val i: Int)
|
||||
|
||||
const val i2: Int = 1
|
||||
const val i: Int = i2
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
@kotlin.internal.LowPriorityInOverloadResolution
|
||||
fun foo(i: Int) = 1
|
||||
|
||||
fun foo(a: Any) = 2
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
@kotlin.internal.LowPriorityInOverloadResolution
|
||||
fun bar(a: String?) = 3
|
||||
|
||||
fun bar(a: Any) = 4
|
||||
|
||||
fun box(): String {
|
||||
if (foo(1) != 2) return "fail1"
|
||||
if (bar(null) != 3) return "fail2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(vararg val p: Int)
|
||||
|
||||
@Ann() class MyClass1
|
||||
@Ann(1) class MyClass2
|
||||
@Ann(1, 2) class MyClass3
|
||||
|
||||
@Ann(*intArrayOf()) class MyClass4
|
||||
@Ann(*intArrayOf(1)) class MyClass5
|
||||
@Ann(*intArrayOf(1, 2)) class MyClass6
|
||||
|
||||
@Ann(p = 1) class MyClass7
|
||||
|
||||
@Ann(p = *intArrayOf()) class MyClass8
|
||||
@Ann(p = *intArrayOf(1)) class MyClass9
|
||||
@Ann(p = *intArrayOf(1, 2)) class MyClass10
|
||||
|
||||
fun box(): String {
|
||||
test(MyClass1::class.java, "")
|
||||
test(MyClass2::class.java, "1")
|
||||
test(MyClass3::class.java, "12")
|
||||
|
||||
test(MyClass4::class.java, "")
|
||||
test(MyClass5::class.java, "1")
|
||||
test(MyClass6::class.java, "12")
|
||||
|
||||
test(MyClass7::class.java, "1")
|
||||
|
||||
test(MyClass8::class.java, "")
|
||||
test(MyClass9::class.java, "1")
|
||||
test(MyClass10::class.java, "12")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun test(klass: Class<*>, expected: String) {
|
||||
val ann = klass.getAnnotation(Ann::class.java)
|
||||
if (ann == null) throw AssertionError("fail: cannot find Ann on ${klass}")
|
||||
|
||||
var result = ""
|
||||
for (i in ann.p) {
|
||||
result += i
|
||||
}
|
||||
|
||||
if (result != expected) {
|
||||
throw AssertionError("fail: expected = ${expected}, actual = ${result}")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun simpleIntArray(): Array<Int> = Array(3) { it }
|
||||
fun simpleDoubleArray(): Array<Double> = Array(3) { it.toDouble() + 0.1 }
|
||||
fun simpleStringArray(): Array<String> = Array(3) { it.toString() }
|
||||
|
||||
fun box(): String {
|
||||
val ia = simpleIntArray()
|
||||
assertEquals(0, ia[0])
|
||||
assertEquals(1, ia[1])
|
||||
assertEquals(2, ia[2])
|
||||
|
||||
val da = simpleDoubleArray()
|
||||
assertEquals(0.1, da[0])
|
||||
assertEquals(1.1, da[1])
|
||||
assertEquals(2.1, da[2])
|
||||
|
||||
val sa = simpleStringArray()
|
||||
assertEquals("0", sa[0])
|
||||
assertEquals("1", sa[1])
|
||||
assertEquals("2", sa[2])
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
val x: Array<List<*>> = arrayOf(listOf(1))
|
||||
val y : Array<in List<String>> = x
|
||||
|
||||
if (y.size != 1) return "fail 1"
|
||||
|
||||
y[0] = listOf("OK")
|
||||
|
||||
return x[0][0] as String
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
val a = Array<Int>(5, {it})
|
||||
val x = a.indices.iterator()
|
||||
while (x.hasNext()) {
|
||||
val i = x.next()
|
||||
if (a[i] != i) return "Fail $i ${a[i]}"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
val a = CharArray(5)
|
||||
val x = a.indices.iterator()
|
||||
while (x.hasNext()) {
|
||||
val i = x.next()
|
||||
if (a[i] != 0.toChar()) return "Fail $i ${a[i]}"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun box() = if(arrayOfNulls<Int>(10).isArrayOf<java.lang.Integer>()) "OK" else "fail"
|
||||
@@ -0,0 +1,6 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun box() : String {
|
||||
val value = (1 to doubleArrayOf(1.0)).second[0]
|
||||
return if (value == 1.0) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun foo(x : Any): String {
|
||||
return if(x is Array<*> && x.isArrayOf<String>()) (x as Array<String>)[0] else "fail"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return foo(arrayOf("OK"))
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun stringMultiArray(): Array<Array<String>> = Array(3) {
|
||||
i -> Array(3) { j -> "$i-$j" }
|
||||
}
|
||||
|
||||
fun stringNullableMultiArray(): Array<Array<String?>> = Array(3) {
|
||||
i -> if (i == 1) Array(3) { j -> "$i-$j" } as Array<String?> else arrayOfNulls<String>(3)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val matrix = stringMultiArray()
|
||||
|
||||
for (i in 0..2) {
|
||||
for (j in 0..2) {
|
||||
assertEquals("$i-$j", matrix[i][j], "matrix")
|
||||
}
|
||||
}
|
||||
|
||||
val matrixNullable = stringNullableMultiArray()
|
||||
|
||||
for (j in 0..2) {
|
||||
assertEquals(null, matrixNullable[0][j], "nullable")
|
||||
assertEquals("1-$j", matrixNullable[1][j], "nullable")
|
||||
assertEquals(null, matrixNullable[2][j], "nullable")
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun <R, T> foo(x : R?, block : (R?) -> T) : T {
|
||||
return block(x)
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
assertEquals(1L, foo(1) { x -> x!!.toLong() })
|
||||
assertEquals(1.toShort(), foo(1) { x -> x!!.toShort() })
|
||||
assertEquals(1.toByte(), foo(1L) { x -> x!!.toByte() })
|
||||
assertEquals(1.toShort(), foo(1L) { x -> x!!.toShort() })
|
||||
assertEquals('a'.toDouble(), foo('a') { x -> x!!.toDouble() })
|
||||
assertEquals(1.0.toByte(), foo(1.0) { x -> x!!.toByte() })
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun <R, T> foo(x : R, y : R, block : (R) -> T) : T {
|
||||
val a = x is Number
|
||||
val b = x is Object
|
||||
|
||||
val b1 = x as Object
|
||||
|
||||
if (a && b) {
|
||||
return block(x)
|
||||
} else {
|
||||
return block(y)
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
assertEquals(1, foo(1, 2) { x -> x as Int })
|
||||
assertEquals("def", foo("abc", "def") { x -> x as String })
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box() : String {
|
||||
val x = LongArray(5)
|
||||
for (i in 0..4) {
|
||||
x[i] = (i + 1).toLong()
|
||||
}
|
||||
|
||||
assertEquals(15L, x.fold(0L) { x, y -> x + y })
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
val result = (1..5).fold(0) { x, y -> x + y }
|
||||
|
||||
assertEquals(15, result)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun test1() {
|
||||
val u = when (true) {
|
||||
true -> 42
|
||||
else -> 1.0
|
||||
}
|
||||
|
||||
assertEquals(42, u)
|
||||
}
|
||||
|
||||
fun test2() {
|
||||
val u = 1L.let {
|
||||
when (it) {
|
||||
is Long -> if (it.toLong() == 2L) it.toLong() else it * 2L // CompilationException
|
||||
else -> it.toDouble()
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(2L, u)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test1()
|
||||
test2()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun checkLongAB5E(x: Long) = assertEquals(0xAB5EL, x)
|
||||
fun checkDouble1(y: Double) = assertEquals(1.0, y)
|
||||
fun checkByte10(z: Byte) = assertEquals(10.toByte(), z)
|
||||
|
||||
fun box(): String {
|
||||
val x = java.lang.Long.valueOf("AB5E", 16)
|
||||
checkLongAB5E(x)
|
||||
|
||||
val y = java.lang.Double.valueOf("1.0")
|
||||
checkDouble1(y)
|
||||
|
||||
val z = java.lang.Byte.valueOf("A", 16)
|
||||
checkByte10(z)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
val x = (10L..50).map { it * 40L }
|
||||
assertEquals(400L, x.first())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun <R, T> foo(x : R?, y : R?, block : (R?) -> T) : T {
|
||||
if (x == null) {
|
||||
return block(x)
|
||||
} else {
|
||||
return block(y)
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
assertEquals(3, foo(1, 2) { x -> if (x != null) 3 else 4 })
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box() : String {
|
||||
|
||||
val result1 = (1..100).count { x -> x % 2 == 0 }
|
||||
val result2 = (1..100).filter { x -> x % 2 == 0 }.size
|
||||
assertEquals(result1, 50)
|
||||
assertEquals(result2, 50)
|
||||
|
||||
val result3 = (1..100).map { x -> 2 * x }.count { x -> x % 2 == 0 }
|
||||
val result4 = (1..100).map { x -> 2 * x }.filter { x -> x % 2 == 0 }.size
|
||||
assertEquals(result3, 100)
|
||||
assertEquals(result4, 100)
|
||||
|
||||
val result5 = (1L..100L).count { x -> x % 2 == 0L }
|
||||
val result6 = (1L..100L).filter { x -> x % 2 == 0L }.size
|
||||
assertEquals(result5, 50)
|
||||
assertEquals(result6, 50)
|
||||
|
||||
val result7 = (1L..100L).map { x -> 2 * x }.count { x -> x % 2 == 0L }
|
||||
val result8 = (1L..100L).map { x -> 2 * x }.filter { x -> x % 2 == 0L }.size
|
||||
assertEquals(result7, 100)
|
||||
assertEquals(result8, 100)
|
||||
|
||||
val result9 = (0..10).reduce { total, next -> total + next }
|
||||
val result10 = (0L..10L).reduce { total, next -> total + next }
|
||||
assertEquals(result9, 55)
|
||||
assertEquals(result10, 55L)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A(val x : Int, val y : A?)
|
||||
|
||||
fun check(a : A?) : Int {
|
||||
return a?.y?.x ?: (a?.x ?: 3)
|
||||
}
|
||||
|
||||
fun checkLeftAssoc(a : A?) : Int {
|
||||
return (a?.y?.x ?: a?.x) ?: 3
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val a1 = A(2, A(1, null))
|
||||
val a2 = A(2, null)
|
||||
val a3 = null
|
||||
|
||||
assertEquals(1, check(a1))
|
||||
assertEquals(2, check(a2))
|
||||
assertEquals(3, check(a3))
|
||||
|
||||
assertEquals(1, checkLeftAssoc(a1))
|
||||
assertEquals(2, checkLeftAssoc(a2))
|
||||
assertEquals(3, checkLeftAssoc(a3))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun <R> foo(x : R, block : (R) -> R) : R {
|
||||
return block(x)
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val result = foo(1) { x -> x + 1 }
|
||||
assertEquals(2, result)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
var result = 0
|
||||
if (1 == 1) {
|
||||
val x: Int? = 1
|
||||
result += x!!
|
||||
}
|
||||
|
||||
assertEquals(1, result)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun returningBoxed() : Int? = 1
|
||||
fun acceptingBoxed(x : Int?) : Int ? = x
|
||||
|
||||
class A(var x : Int? = null)
|
||||
|
||||
fun box() : String {
|
||||
assertEquals(1, returningBoxed())
|
||||
assertEquals(1, acceptingBoxed(1))
|
||||
|
||||
val a = A()
|
||||
a.x = 1
|
||||
assertEquals(1, a.x)
|
||||
|
||||
val b = Array<Int?>(1, { null })
|
||||
b[0] = 1
|
||||
assertEquals(1, b[0])
|
||||
|
||||
val x: Int? = 1
|
||||
assertEquals(1, x!!.hashCode())
|
||||
|
||||
val y: Int? = 1000
|
||||
val z: Int? = 1000
|
||||
val res = y === z
|
||||
|
||||
val c1: Any = if (1 == 1) 0 else "abc"
|
||||
val c2: Any = if (1 != 1) 0 else "abc"
|
||||
assertEquals(0, c1)
|
||||
assertEquals("abc", c2)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun <R, T> foo(x : R, block : (R) -> T) : T {
|
||||
var y = x
|
||||
var z = y
|
||||
z = x
|
||||
return block(z)
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
assertEquals(1, foo(1) { x -> x })
|
||||
assertEquals(1f, foo(1f) { x -> x })
|
||||
assertEquals(1L, foo(1L) { x -> x })
|
||||
assertEquals(1.toDouble(), foo(1.toDouble()) { x -> x })
|
||||
assertEquals(1.toShort(), foo(1.toShort()) { x -> x })
|
||||
assertEquals(1.toByte(), foo(1.toByte()) { x -> x })
|
||||
assertEquals('a', foo('a') { x -> x })
|
||||
assertEquals(true, foo(true) { x -> x })
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.jvm.internal.FunctionImpl
|
||||
|
||||
fun test(f: Function<*>, arity: Int) {
|
||||
assertEquals(arity, (f as FunctionImpl).getArity())
|
||||
}
|
||||
|
||||
fun foo(s: String, i: Int) {}
|
||||
class A {
|
||||
fun bar(s: String, i: Int) {}
|
||||
}
|
||||
fun Double.baz(s: String, i: Int) {}
|
||||
|
||||
fun box(): String {
|
||||
test(::foo, 2)
|
||||
test(A::bar, 3)
|
||||
test(Double::baz, 3)
|
||||
|
||||
test(::box, 0)
|
||||
|
||||
fun local(x: Int) {}
|
||||
test(::local, 1)
|
||||
|
||||
test(fun(s: String) = s, 1)
|
||||
test(fun(){}, 0)
|
||||
test({}, 0)
|
||||
test({x: Int -> x}, 1)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
+57
@@ -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"
|
||||
}
|
||||
+130
@@ -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"
|
||||
}
|
||||
+111
@@ -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"
|
||||
}
|
||||
+141
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// TODO: Enable for JS when it supports local classes.
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun testFun1(str: String): String {
|
||||
val local = str
|
||||
|
||||
class Local {
|
||||
fun foo() = str
|
||||
}
|
||||
|
||||
val list = listOf(0).map { Local() }
|
||||
return list[0].foo()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return when {
|
||||
testFun1("test1") != "test1" -> "Fail #1"
|
||||
else -> "OK"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun concatNonNulls(strings: List<String?>): String {
|
||||
var result = ""
|
||||
for (str in strings) {
|
||||
result += str?:continue
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = concatNonNulls(listOf("abc", null, null, "", null, "def"))
|
||||
if (test != "abcdef") return "Failed: test=$test"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
|
||||
import java.util.LinkedList
|
||||
|
||||
fun ok1(): Boolean {
|
||||
val queue = LinkedList(listOf(1, 2, 3))
|
||||
while (!queue.isEmpty()) {
|
||||
queue.poll()
|
||||
for (y in 1..3) {
|
||||
if (queue.contains(y)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun ok2(): Boolean {
|
||||
val queue = LinkedList(listOf(1, 2, 3))
|
||||
val array = arrayOf(1, 2, 3)
|
||||
while (!queue.isEmpty()) {
|
||||
queue.poll()
|
||||
for (y in array) {
|
||||
if (queue.contains(y)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun ok3(): Boolean {
|
||||
val queue = LinkedList(listOf(1, 2, 3))
|
||||
while (!queue.isEmpty()) {
|
||||
queue.poll()
|
||||
var x = 0
|
||||
do {
|
||||
x++
|
||||
if (x == 2) return true
|
||||
} while (x < 2)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (!ok1()) return "Fail #1"
|
||||
if (!ok2()) return "Fail #2"
|
||||
if (!ok3()) return "Fail #3"
|
||||
return "OK"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
data class B(val x: Int) {
|
||||
fun equals(other: B): Boolean = false
|
||||
}
|
||||
|
||||
data class C(val x: Int) {
|
||||
fun equals(): Boolean = false
|
||||
}
|
||||
|
||||
data class D(val x: Int) {
|
||||
fun equals(other: Any?, another: String): Boolean = false
|
||||
}
|
||||
|
||||
data class E(val x: Int) {
|
||||
fun equals(x: E): Boolean = false
|
||||
override fun equals(x: Any?): Boolean = false
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
B::class.java.getDeclaredMethod("equals", Any::class.java)
|
||||
B::class.java.getDeclaredMethod("equals", B::class.java)
|
||||
|
||||
C::class.java.getDeclaredMethod("equals", Any::class.java)
|
||||
C::class.java.getDeclaredMethod("equals")
|
||||
|
||||
D::class.java.getDeclaredMethod("equals", Any::class.java)
|
||||
D::class.java.getDeclaredMethod("equals", Any::class.java, String::class.java)
|
||||
|
||||
E::class.java.getDeclaredMethod("equals", Any::class.java)
|
||||
E::class.java.getDeclaredMethod("equals", E::class.java)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
data class A(val x: Int) {
|
||||
fun hashCode(other: Any): Int = 0
|
||||
}
|
||||
|
||||
data class B(val x: Int) {
|
||||
fun hashCode(other: B, another: Any): Int = 0
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
A::class.java.getDeclaredMethod("hashCode")
|
||||
A::class.java.getDeclaredMethod("hashCode", Any::class.java)
|
||||
|
||||
B::class.java.getDeclaredMethod("hashCode")
|
||||
B::class.java.getDeclaredMethod("hashCode", B::class.java, Any::class.java)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
data class A(val x: Int) {
|
||||
fun toString(other: Any): String = ""
|
||||
}
|
||||
|
||||
data class B(val x: Int) {
|
||||
fun toString(other: B, another: Any): String = ""
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
A::class.java.getDeclaredMethod("toString")
|
||||
A::class.java.getDeclaredMethod("toString", Any::class.java)
|
||||
|
||||
B::class.java.getDeclaredMethod("toString")
|
||||
B::class.java.getDeclaredMethod("toString", B::class.java, Any::class.java)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun foo(): Int {
|
||||
return 1
|
||||
// val xyz has empty live range because everything after return will be removed as dead
|
||||
val xyz = 1
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(1, foo())
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A(value: Int = 1)
|
||||
|
||||
fun box(): String {
|
||||
val constructors = A::class.java.getConstructors().filter { !it.isSynthetic() }
|
||||
return if (constructors.size == 2) "OK" else constructors.size.toString()
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A(val a: Int = 1,
|
||||
val b: Int = 2,
|
||||
val c: Int = 3,
|
||||
val d: Int = 4,
|
||||
val e: Int = 5,
|
||||
val f: Int = 6,
|
||||
val g: Int = 7,
|
||||
val h: Int = 8,
|
||||
val i: Int = 9,
|
||||
val j: Int = 10,
|
||||
val k: Int = 11,
|
||||
val l: Int = 12,
|
||||
val m: Int = 13,
|
||||
val n: Int = 14,
|
||||
val o: Int = 15,
|
||||
val p: Int = 16,
|
||||
val q: Int = 17,
|
||||
val r: Int = 18,
|
||||
val s: Int = 19,
|
||||
val t: Int = 20,
|
||||
val u: Int = 21,
|
||||
val v: Int = 22,
|
||||
val w: Int = 23,
|
||||
val x: Int = 24,
|
||||
val y: Int = 25,
|
||||
val z: Int = 26,
|
||||
val aa: Int = 27,
|
||||
val bb: Int = 28,
|
||||
val cc: Int = 29,
|
||||
val dd: Int = 30,
|
||||
val ee: Int = 31,
|
||||
val ff: Int = 32) {
|
||||
override fun toString(): String {
|
||||
return "$a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p $q $r $s $t $u $v $w $x $y $z $aa $bb $cc $dd $ee $ff"
|
||||
}
|
||||
}
|
||||
|
||||
class B(val a: Int = 1,
|
||||
val b: Int = 2,
|
||||
val c: Int = 3,
|
||||
val d: Int = 4,
|
||||
val e: Int = 5,
|
||||
val f: Int = 6,
|
||||
val g: Int = 7,
|
||||
val h: Int = 8,
|
||||
val i: Int = 9,
|
||||
val j: Int = 10,
|
||||
val k: Int = 11,
|
||||
val l: Int = 12,
|
||||
val m: Int = 13,
|
||||
val n: Int = 14,
|
||||
val o: Int = 15,
|
||||
val p: Int = 16,
|
||||
val q: Int = 17,
|
||||
val r: Int = 18,
|
||||
val s: Int = 19,
|
||||
val t: Int = 20,
|
||||
val u: Int = 21,
|
||||
val v: Int = 22,
|
||||
val w: Int = 23,
|
||||
val x: Int = 24,
|
||||
val y: Int = 25,
|
||||
val z: Int = 26,
|
||||
val aa: Int = 27,
|
||||
val bb: Int = 28,
|
||||
val cc: Int = 29,
|
||||
val dd: Int = 30,
|
||||
val ee: Int = 31,
|
||||
val ff: Int = 32,
|
||||
val gg: Int = 33,
|
||||
val hh: Int = 34,
|
||||
val ii: Int = 35,
|
||||
val jj: Int = 36,
|
||||
val kk: Int = 37,
|
||||
val ll: Int = 38,
|
||||
val mm: Int = 39,
|
||||
val nn: Int = 40) {
|
||||
override fun toString(): String {
|
||||
return "$a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p $q $r $s $t $u $v $w $x $y $z $aa $bb $cc $dd $ee $ff " +
|
||||
"$gg $hh $ii $jj $kk $ll $mm $nn"
|
||||
}
|
||||
}
|
||||
|
||||
class C(val a: Int = 1,
|
||||
val b: Int = 2,
|
||||
val c: Int = 3,
|
||||
val d: Int = 4,
|
||||
val e: Int = 5,
|
||||
val f: Int = 6,
|
||||
val g: Int = 7,
|
||||
val h: Int = 8,
|
||||
val i: Int = 9,
|
||||
val j: Int = 10,
|
||||
val k: Int = 11,
|
||||
val l: Int = 12,
|
||||
val m: Int = 13,
|
||||
val n: Int = 14,
|
||||
val o: Int = 15,
|
||||
val p: Int = 16,
|
||||
val q: Int = 17,
|
||||
val r: Int = 18,
|
||||
val s: Int = 19,
|
||||
val t: Int = 20,
|
||||
val u: Int = 21,
|
||||
val v: Int = 22,
|
||||
val w: Int = 23,
|
||||
val x: Int = 24,
|
||||
val y: Int = 25,
|
||||
val z: Int = 26,
|
||||
val aa: Int = 27,
|
||||
val bb: Int = 28,
|
||||
val cc: Int = 29,
|
||||
val dd: Int = 30,
|
||||
val ee: Int = 31,
|
||||
val ff: Int = 32,
|
||||
val gg: Int = 33,
|
||||
val hh: Int = 34,
|
||||
val ii: Int = 35,
|
||||
val jj: Int = 36,
|
||||
val kk: Int = 37,
|
||||
val ll: Int = 38,
|
||||
val mm: Int = 39,
|
||||
val nn: Int = 40,
|
||||
val oo: Int = 41,
|
||||
val pp: Int = 42,
|
||||
val qq: Int = 43,
|
||||
val rr: Int = 44,
|
||||
val ss: Int = 45,
|
||||
val tt: Int = 46,
|
||||
val uu: Int = 47,
|
||||
val vv: Int = 48,
|
||||
val ww: Int = 49,
|
||||
val xx: Int = 50,
|
||||
val yy: Int = 51,
|
||||
val zz: Int = 52,
|
||||
val aaa: Int = 53,
|
||||
val bbb: Int = 54,
|
||||
val ccc: Int = 55,
|
||||
val ddd: Int = 56,
|
||||
val eee: Int = 57,
|
||||
val fff: Int = 58,
|
||||
val ggg: Int = 59,
|
||||
val hhh: Int = 60,
|
||||
val iii: Int = 61,
|
||||
val jjj: Int = 62,
|
||||
val kkk: Int = 63,
|
||||
val lll: Int = 64,
|
||||
val mmm: Int = 65,
|
||||
val nnn: Int = 66,
|
||||
val ooo: Int = 67,
|
||||
val ppp: Int = 68,
|
||||
val qqq: Int = 69,
|
||||
val rrr: Int = 70) {
|
||||
override fun toString(): String {
|
||||
return "$a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p $q $r $s $t $u $v $w $x $y $z $aa $bb $cc $dd $ee $ff $gg $hh $ii $jj $kk " +
|
||||
"$ll $mm $nn $oo $pp $qq $rr $ss $tt $uu $vv $ww $xx $yy $zz $aaa $bbb $ccc $ddd $eee $fff $ggg $hhh $iii $jjj $kkk $lll " +
|
||||
"$mmm $nnn $ooo $ppp $qqq $rrr"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test1 = A(4, e = 8, f = 15, w = 16, aa = 23, ff = 42).toString()
|
||||
val test2 = A::class.java.newInstance().toString()
|
||||
val test3 = A(32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, q = 16, r = 15, s = 14, t = 13,
|
||||
u = 12, v = 11, w = 10, x = 9, y = 8, z = 7, aa = 6, bb = 5, cc = 4, dd = 3, ee = 2, ff = 1).toString()
|
||||
if (test1 != "4 2 3 4 8 15 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 16 24 25 26 23 28 29 30 31 42") {
|
||||
return "test1 = $test1"
|
||||
}
|
||||
if (test2 != "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32") {
|
||||
return "test2 = $test2"
|
||||
}
|
||||
if (test3 != "32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1") {
|
||||
return "test3 = $test3"
|
||||
}
|
||||
|
||||
val test4 = B(54, 217, h = 236, l = 18, q = 3216, u = 8, aa = 22, ff = 33, jj = 44, mm = 55).toString()
|
||||
val test5 = B::class.java.newInstance().toString()
|
||||
val test6 = B(40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, u = 20, v = 19,
|
||||
w = 18, x = 17, y = 16, z = 15, aa = 14, bb = 13, cc = 12, dd = 11, ee = 10, ff = 9, gg = 8, hh = 7, ii = 6,
|
||||
jj = 5, kk = 4, ll = 3, mm = 2, nn = 1).toString()
|
||||
if (test4 != "54 217 3 4 5 6 7 236 9 10 11 18 13 14 15 16 3216 18 19 20 8 22 23 24 25 26 22 28 29 30 31 33 33 34 35 44 37 38 55 40") {
|
||||
return "test4 = $test4"
|
||||
}
|
||||
if (test5 != "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40") {
|
||||
return "test5 = $test5"
|
||||
}
|
||||
if (test6 != "40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1") {
|
||||
return "test6 = $test6"
|
||||
}
|
||||
|
||||
val test7 = C(5, f = 3, w = 1, aa = 71, nn = 2, qq = 15, ww = 97, aaa = 261258, iii = 3, nnn = 8, rrr = 7).toString()
|
||||
val test8 = C::class.java.newInstance().toString()
|
||||
val test9 = C(70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41,
|
||||
40, 39, 38, 37, 36, jj = 35, kk = 34, ll = 33, mm = 32, nn = 31, oo = 30, pp = 29, qq = 28, rr = 27, ss = 26, tt = 25,
|
||||
uu = 24, vv = 23, ww = 22, xx = 21, yy = 20, zz = 19, aaa = 18, bbb = 17, ccc = 16, ddd = 15, eee = 14, fff = 13,
|
||||
ggg = 12, hhh = 11, iii = 10, jjj = 9, kkk = 8, lll = 7, mmm = 6, nnn = 5, ooo = 4, ppp = 3, qqq = 2, rrr = 1).toString()
|
||||
if (test7 != "5 2 3 4 5 3 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 1 24 25 26 71 28 29 30 31 32 33 34 35 36 37 38 39 2 41 42 15 " +
|
||||
"44 45 46 47 48 97 50 51 52 261258 54 55 56 57 58 59 60 3 62 63 64 65 8 67 68 69 7") {
|
||||
return "test7 = $test7"
|
||||
}
|
||||
if (test8 != "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 " +
|
||||
"43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70") {
|
||||
return "test8 = $test8"
|
||||
}
|
||||
if (test9 != "70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 " +
|
||||
"31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1") {
|
||||
return "test9 = $test9"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
return if (A().run() == "Aabc") "OK" else "fail"
|
||||
}
|
||||
|
||||
public class A {
|
||||
fun run() =
|
||||
with ("abc") {
|
||||
show()
|
||||
}
|
||||
|
||||
private fun String.show(p: Boolean = false): String = getName() + this
|
||||
|
||||
private fun getName() = "A"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun def(i: Int = 0): Int {
|
||||
return i;
|
||||
}
|
||||
|
||||
fun box():String {
|
||||
val clazz = Class.forName("SuperCallCheckKt")
|
||||
|
||||
val method = clazz.getMethod("def\$default", Int::class.java, Int::class.java, Any::class.java)
|
||||
val result = method.invoke(null, -1, 1, null)
|
||||
|
||||
if (result != 0) return "fail 1: $result"
|
||||
|
||||
var failed = false
|
||||
try {
|
||||
method.invoke(null, -1, 1, "fail")
|
||||
} catch(e: Exception) {
|
||||
val cause = e.cause
|
||||
if (cause is java.lang.UnsupportedOperationException &&
|
||||
cause.message!!.startsWith("Super calls")) {
|
||||
failed = true
|
||||
}
|
||||
}
|
||||
|
||||
return if (!failed) "fail" else "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// WITH_RUNTIME
|
||||
// See KT-10107: 'Variable must be initialized' for delegate with private set
|
||||
|
||||
class My {
|
||||
var delegate: String by kotlin.properties.Delegates.notNull()
|
||||
private set
|
||||
|
||||
init {
|
||||
delegate = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = My().delegate
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
interface T {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = "OK"
|
||||
val t = object : T {
|
||||
val foo by lazy {
|
||||
a
|
||||
}
|
||||
}
|
||||
return t.foo
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
object X {
|
||||
public var O: String
|
||||
by Delegates.observable("O") { prop, old, new -> }
|
||||
private set
|
||||
}
|
||||
|
||||
open class A {
|
||||
public var K: String
|
||||
by Delegates.observable("") { prop, old, new -> }
|
||||
protected set
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
init {
|
||||
K = "K"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String =
|
||||
X.O + B().K
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
open class A<T : Any> {
|
||||
protected var value: T by Delegates.notNull()
|
||||
private set
|
||||
}
|
||||
|
||||
class B : A<Int>()
|
||||
|
||||
fun box(): String {
|
||||
B()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
// WITH_REFLECT
|
||||
// FULL_JDK
|
||||
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
import kotlin.reflect.*
|
||||
|
||||
object Delegate {
|
||||
operator fun getValue(t: Any?, p: KProperty<*>): String {
|
||||
(p as? KProperty0<String>)?.get()
|
||||
(p as? KProperty1<O, String>)?.get(O)
|
||||
(p as? KProperty2<O, O, String>)?.get(O, O)
|
||||
return "Fail"
|
||||
}
|
||||
|
||||
operator fun setValue(t: Any?, p: KProperty<*>, v: String) {
|
||||
(p as? KMutableProperty0<String>)?.set(v)
|
||||
(p as? KMutableProperty1<O, String>)?.set(O, v)
|
||||
(p as? KMutableProperty2<O, O, String>)?.set(O, O, v)
|
||||
}
|
||||
}
|
||||
|
||||
var topLevel: String by Delegate
|
||||
object O {
|
||||
var member: String by Delegate
|
||||
var O.memExt: String by Delegate
|
||||
}
|
||||
|
||||
fun check(lambda: () -> Unit) {
|
||||
try {
|
||||
lambda()
|
||||
} catch (e: Throwable) {
|
||||
if (e !is InvocationTargetException && e !is StackOverflowError) {
|
||||
throw AssertionError("The current implementation uses reflection to get the value of the property," +
|
||||
"so either InvocationTargetException or StackOverflowError should have happened, but was: ${e}")
|
||||
}
|
||||
return
|
||||
}
|
||||
throw AssertionError("Getting the property value with .get() from getValue() or setting it with .set() in setValue() " +
|
||||
"is effectively an endless recursion and should fail")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check { topLevel }
|
||||
check { topLevel = "" }
|
||||
check { O.member }
|
||||
check { O.member = "" }
|
||||
with (O) {
|
||||
check { O.memExt }
|
||||
check { O.memExt = "" }
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// WITH_REFLECT
|
||||
// TODO: replace with WITH_RUNTIME once KT-11316 is fixed
|
||||
|
||||
import java.util.*
|
||||
import kotlin.reflect.*
|
||||
|
||||
val properties = HashSet<KProperty<*>>()
|
||||
|
||||
object Delegate {
|
||||
operator fun getValue(t: Any?, p: KProperty<*>): String {
|
||||
properties.add(p)
|
||||
return ""
|
||||
}
|
||||
|
||||
operator fun setValue(t: Any?, p: KProperty<*>, v: String) {
|
||||
properties.add(p)
|
||||
}
|
||||
}
|
||||
|
||||
var topLevel: String by Delegate
|
||||
object O {
|
||||
var member: String by Delegate
|
||||
var O.memExt: String by Delegate
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
topLevel = ""
|
||||
O.member = ""
|
||||
with (O) {
|
||||
O.memExt = ""
|
||||
}
|
||||
|
||||
for (p in HashSet(properties)) {
|
||||
// None of these should fail
|
||||
|
||||
(p as? KProperty0<String>)?.get()
|
||||
(p as? KProperty1<O, String>)?.get(O)
|
||||
(p as? KProperty2<O, O, String>)?.get(O, O)
|
||||
|
||||
(p as? KMutableProperty0<String>)?.set("")
|
||||
(p as? KMutableProperty1<O, String>)?.set(O, "")
|
||||
(p as? KMutableProperty2<O, O, String>)?.set(O, O, "")
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import Game.*
|
||||
|
||||
enum class Game {
|
||||
ROCK,
|
||||
PAPER,
|
||||
SCISSORS,
|
||||
LIZARD,
|
||||
SPOCK
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = arrayOf(LIZARD, SCISSORS, SPOCK, ROCK, PAPER)
|
||||
a.sort()
|
||||
val str = a.joinToString(" ")
|
||||
return if (str == "ROCK PAPER SCISSORS LIZARD SPOCK") "OK" else "Fail: $str"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
package test
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(val c1: Int)
|
||||
|
||||
@Ann('a' - 'a') class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val annotation = MyClass::class.java.getAnnotation(Ann::class.java)!!
|
||||
if (annotation.c1 != 0) return "fail : expected = ${1}, actual = ${annotation.c1}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val b: Byte,
|
||||
val s: Short,
|
||||
val i: Int,
|
||||
val l: Long
|
||||
)
|
||||
|
||||
@Ann(1 / 1, 1 / 1, 1 / 1, 1 / 1) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val annotation = MyClass::class.java.getAnnotation(Ann::class.java)!!
|
||||
if (annotation.b != 1.toByte()) return "fail 1"
|
||||
if (annotation.s != 1.toShort()) return "fail 2"
|
||||
if (annotation.i != 1) return "fail 2"
|
||||
if (annotation.l != 1.toLong()) return "fail 2"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// EXPECTED: Ann[b = IntegerValueType(1): IntegerValueType(1), i = IntegerValueType(1): IntegerValueType(1), l = IntegerValueType(1): IntegerValueType(1), s = IntegerValueType(1): IntegerValueType(1)]
|
||||
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val p1: Int,
|
||||
val p2: Short,
|
||||
val p3: Byte,
|
||||
val p4: Int,
|
||||
val p5: Int,
|
||||
val p6: Int
|
||||
)
|
||||
|
||||
val prop1: Int = 1 or 1
|
||||
val prop2: Short = 1 and 1
|
||||
val prop3: Byte = 1 xor 1
|
||||
val prop4: Int = 1 shl 1
|
||||
val prop5: Int = 1 shr 1
|
||||
val prop6: Int = 1 ushr 1
|
||||
|
||||
@Ann(1 or 1, 1 and 1, 1 xor 1, 1 shl 1, 1 shr 1, 1 ushr 1) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val annotation = MyClass::class.java.getAnnotation(Ann::class.java)!!
|
||||
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
|
||||
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
|
||||
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
|
||||
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
|
||||
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
|
||||
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
abstract class BaseClass {
|
||||
protected open val menuId: Int = 0
|
||||
|
||||
public fun run(): Pair<String, Boolean> =
|
||||
"$menuId" to (menuId == 0)
|
||||
}
|
||||
|
||||
class ImplClass: BaseClass() {
|
||||
override val menuId: Int = 3
|
||||
}
|
||||
|
||||
public fun box(): String {
|
||||
val result = ImplClass().run()
|
||||
|
||||
if (result != ("3" to false)) return "Fail: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val p1: Int,
|
||||
val p2: Int,
|
||||
val p3: Int,
|
||||
val p4: Int,
|
||||
val p5: Long,
|
||||
val p6: Long
|
||||
)
|
||||
|
||||
@Ann(
|
||||
p1 = java.lang.Byte.MAX_VALUE + 1,
|
||||
p2 = java.lang.Short.MAX_VALUE + 1,
|
||||
p3 = java.lang.Integer.MAX_VALUE + 1,
|
||||
p4 = java.lang.Integer.MAX_VALUE + 1,
|
||||
p5 = java.lang.Integer.MAX_VALUE + 1.toLong(),
|
||||
p6 = java.lang.Long.MAX_VALUE + 1
|
||||
) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val annotation = MyClass::class.java.getAnnotation(Ann::class.java)!!
|
||||
if (annotation.p1 != 128) return "fail 1, expected = ${128}, actual = ${annotation.p1}"
|
||||
if (annotation.p2 != 32768) return "fail 2, expected = ${32768}, actual = ${annotation.p2}"
|
||||
if (annotation.p3 != -2147483648) return "fail 3, expected = ${-2147483648}, actual = ${annotation.p3}"
|
||||
if (annotation.p4 != -2147483648) return "fail 4, expected = ${-2147483648}, actual = ${annotation.p4}"
|
||||
if (annotation.p5 != 2147483648.toLong()) return "fail 5, expected = ${2147483648}, actual = ${annotation.p5}"
|
||||
if (annotation.p6 != java.lang.Long.MAX_VALUE + 1) return "fail 5, expected = ${java.lang.Long.MAX_VALUE + 1}, actual = ${annotation.p6}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val p1: Int,
|
||||
val p2: Byte,
|
||||
val p4: Int,
|
||||
val p5: Int
|
||||
)
|
||||
|
||||
@Ann(
|
||||
p1 = java.lang.Byte.MAX_VALUE + 1,
|
||||
p2 = 1 + 1,
|
||||
p4 = 1 + 1,
|
||||
p5 = 1.toByte() + 1
|
||||
) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val annotation = MyClass::class.java.getAnnotation(Ann::class.java)!!
|
||||
if (annotation.p1 != 128) return "fail 1, expected = ${128}, actual = ${annotation.p1}"
|
||||
if (annotation.p2 != 2.toByte()) return "fail 2, expected = ${2}, actual = ${annotation.p2}"
|
||||
if (annotation.p4 != 2) return "fail 4, expected = ${2}, actual = ${annotation.p4}"
|
||||
if (annotation.p5 != 2) return "fail 5, expected = ${2}, actual = ${annotation.p5}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val p1: Int,
|
||||
val p2: Int,
|
||||
val p4: Long,
|
||||
val p5: Int
|
||||
)
|
||||
|
||||
@Ann(
|
||||
p1 = java.lang.Integer.MAX_VALUE + 1,
|
||||
p2 = 1 + 1,
|
||||
p4 = 1 + 1,
|
||||
p5 = 1.toInt() + 1.toInt()
|
||||
) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val annotation = MyClass::class.java.getAnnotation(Ann::class.java)!!
|
||||
if (annotation.p1 != -2147483648) return "fail 1, expected = ${-2147483648}, actual = ${annotation.p1}"
|
||||
if (annotation.p2 != 2) return "fail 2, expected = ${2}, actual = ${annotation.p2}"
|
||||
if (annotation.p4 != 2.toLong()) return "fail 4, expected = ${2}, actual = ${annotation.p4}"
|
||||
if (annotation.p5 != 2) return "fail 5, expected = ${2}, actual = ${annotation.p5}"
|
||||
return "OK"
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val p1: Byte,
|
||||
val p2: Short,
|
||||
val p3: Int,
|
||||
val p4: Long,
|
||||
val p5: Double,
|
||||
val p6: Float
|
||||
)
|
||||
|
||||
val prop1: Byte = 1 - 1
|
||||
val prop2: Short = 1 - 1
|
||||
val prop3: Int = 1 - 1
|
||||
val prop4: Long = 1 - 1
|
||||
val prop5: Double = 1.0 - 1.0
|
||||
val prop6: Float = 1.0.toFloat() - 1.0.toFloat()
|
||||
|
||||
@Ann(1 - 1, 1 - 1, 1 - 1, 1 - 1, 1.0 - 1.0, 1.0.toFloat() - 1.0.toFloat()) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val annotation = MyClass::class.java.getAnnotation(Ann::class.java)!!
|
||||
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
|
||||
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
|
||||
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
|
||||
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
|
||||
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
|
||||
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
|
||||
return "OK"
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val p1: Byte,
|
||||
val p2: Short,
|
||||
val p3: Int,
|
||||
val p4: Long,
|
||||
val p5: Double,
|
||||
val p6: Float
|
||||
)
|
||||
|
||||
val prop1: Byte = 1 % 1
|
||||
val prop2: Short = 1 % 1
|
||||
val prop3: Int = 1 % 1
|
||||
val prop4: Long = 1 % 1
|
||||
val prop5: Double = 1.0 % 1.0
|
||||
val prop6: Float = 1.0.toFloat() % 1.0.toFloat()
|
||||
|
||||
@Ann(1 % 1, 1 % 1, 1 % 1, 1 % 1, 1.0 % 1.0, 1.0.toFloat() % 1.0.toFloat()) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val annotation = MyClass::class.java.getAnnotation(Ann::class.java)!!
|
||||
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
|
||||
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
|
||||
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
|
||||
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
|
||||
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
|
||||
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val p1: Byte,
|
||||
val p2: Short,
|
||||
val p3: Int,
|
||||
val p4: Long,
|
||||
val p5: Double,
|
||||
val p6: Float
|
||||
)
|
||||
|
||||
val prop1: Byte = 1 * 1
|
||||
val prop2: Short = 1 * 1
|
||||
val prop3: Int = 1 * 1
|
||||
val prop4: Long = 1 * 1
|
||||
val prop5: Double = 1.0 * 1.0
|
||||
val prop6: Float = 1.0.toFloat() * 1.0.toFloat()
|
||||
|
||||
@Ann(1 * 1, 1 * 1, 1 * 1, 1 * 1, 1.0 * 1.0, 1.0.toFloat() * 1.0.toFloat()) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val annotation = MyClass::class.java.getAnnotation(Ann::class.java)!!
|
||||
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
|
||||
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
|
||||
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
|
||||
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
|
||||
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
|
||||
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val p1: Byte,
|
||||
val p2: Short,
|
||||
val p3: Int,
|
||||
val p4: Long,
|
||||
val p5: Double,
|
||||
val p6: Float
|
||||
)
|
||||
|
||||
val prop1: Byte = (1 + 2) * 2
|
||||
val prop2: Short = (1 + 2) * 2
|
||||
val prop3: Int = (1 + 2) * 2
|
||||
val prop4: Long = (1 + 2) * 2
|
||||
val prop5: Double = (1.0 + 2) * 2
|
||||
val prop6: Float = (1.toFloat() + 2) * 2
|
||||
|
||||
@Ann((1 + 2) * 2, (1 + 2) * 2, (1 + 2) * 2, (1 + 2) * 2, (1.0 + 2) * 2, (1.toFloat() + 2) * 2) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val annotation = MyClass::class.java.getAnnotation(Ann::class.java)!!
|
||||
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
|
||||
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
|
||||
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
|
||||
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
|
||||
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
|
||||
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
|
||||
return "OK"
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val p1: Byte,
|
||||
val p2: Short,
|
||||
val p3: Int,
|
||||
val p4: Long,
|
||||
val p5: Double,
|
||||
val p6: Float
|
||||
)
|
||||
|
||||
val prop1: Byte = 1 + 1
|
||||
val prop2: Short = 1 + 1
|
||||
val prop3: Int = 1 + 1
|
||||
val prop4: Long = 1 + 1
|
||||
val prop5: Double = 1.0 + 1.0
|
||||
val prop6: Float = 1.0.toFloat() + 1.0.toFloat()
|
||||
|
||||
@Ann(1 + 1, 1 + 1, 1 + 1, 1 + 1, 1.0 + 1.0, 1.0.toFloat() + 1.0.toFloat()) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val annotation = MyClass::class.java.getAnnotation(Ann::class.java)!!
|
||||
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
|
||||
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
|
||||
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
|
||||
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
|
||||
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
|
||||
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val p1: Int,
|
||||
val p2: Int,
|
||||
val p3: Int,
|
||||
val p4: Int,
|
||||
val p5: Int
|
||||
)
|
||||
|
||||
const val prop1: Int = 1.plus(1)
|
||||
const val prop2: Int = 1.minus(1)
|
||||
const val prop3: Int = 1.times(1)
|
||||
const val prop4: Int = 1.div(1)
|
||||
const val prop5: Int = 1.mod(1)
|
||||
|
||||
@Ann(prop1, prop2, prop3, prop4, prop5) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val annotation = MyClass::class.java.getAnnotation(Ann::class.java)!!
|
||||
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
|
||||
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
|
||||
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
|
||||
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
|
||||
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val p1: Byte,
|
||||
val p2: Short,
|
||||
val p3: Int,
|
||||
val p4: Long,
|
||||
val p5: Double,
|
||||
val p6: Float
|
||||
)
|
||||
|
||||
const val prop1: Byte = -1
|
||||
const val prop2: Short = -1
|
||||
const val prop3: Int = -1
|
||||
const val prop4: Long = -1
|
||||
const val prop5: Double = -1.0
|
||||
const val prop6: Float = -1.0.toFloat()
|
||||
|
||||
@Ann(prop1, prop2, prop3, prop4, prop5, prop6) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val annotation = MyClass::class.java.getAnnotation(Ann::class.java)!!
|
||||
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
|
||||
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
|
||||
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
|
||||
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
|
||||
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
|
||||
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Ann(
|
||||
val p1: Byte,
|
||||
val p2: Short,
|
||||
val p3: Int,
|
||||
val p4: Long,
|
||||
val p5: Double,
|
||||
val p6: Float
|
||||
)
|
||||
|
||||
const val prop1: Byte = +1
|
||||
const val prop2: Short = +1
|
||||
const val prop3: Int = +1
|
||||
const val prop4: Long = +1
|
||||
const val prop5: Double = +1.0
|
||||
const val prop6: Float = +1.0.toFloat()
|
||||
|
||||
@Ann(prop1, prop2, prop3, prop4, prop5, prop6) class MyClass
|
||||
|
||||
fun box(): String {
|
||||
val annotation = MyClass::class.java.getAnnotation(Ann::class.java)!!
|
||||
if (annotation.p1 != prop1) return "fail 1, expected = ${prop1}, actual = ${annotation.p1}"
|
||||
if (annotation.p2 != prop2) return "fail 2, expected = ${prop2}, actual = ${annotation.p2}"
|
||||
if (annotation.p3 != prop3) return "fail 3, expected = ${prop3}, actual = ${annotation.p3}"
|
||||
if (annotation.p4 != prop4) return "fail 4, expected = ${prop4}, actual = ${annotation.p4}"
|
||||
if (annotation.p5 != prop5) return "fail 5, expected = ${prop5}, actual = ${annotation.p5}"
|
||||
if (annotation.p6 != prop6) return "fail 6, expected = ${prop6}, actual = ${annotation.p6}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
|
||||
package foo
|
||||
|
||||
class WithNative {
|
||||
companion object {
|
||||
@JvmStatic external fun bar(l: Long, s: String): Double
|
||||
}
|
||||
}
|
||||
|
||||
object ObjWithNative {
|
||||
@JvmStatic external fun bar(l: Long, s: String): Double
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var d = 0.0
|
||||
try {
|
||||
d = WithNative.bar(1, "")
|
||||
return "Link error expected"
|
||||
}
|
||||
catch (e: java.lang.UnsatisfiedLinkError) {
|
||||
if (e.message != "foo.WithNative.bar(JLjava/lang/String;)D") return "Fail 1: " + e.message
|
||||
}
|
||||
|
||||
try {
|
||||
d = ObjWithNative.bar(1, "")
|
||||
return "Link error expected on object"
|
||||
}
|
||||
catch (e: java.lang.UnsatisfiedLinkError) {
|
||||
if (e.message != "foo.ObjWithNative.bar(JLjava/lang/String;)D") return "Fail 2: " + e.message
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
|
||||
class C {
|
||||
companion object {
|
||||
private @JvmStatic external fun foo()
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
foo()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
C().bar()
|
||||
return "Link error expected"
|
||||
}
|
||||
catch (e: java.lang.UnsatisfiedLinkError) {
|
||||
if (e.message != "C.foo()V") return "Fail 1: " + e.message
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
|
||||
package foo
|
||||
|
||||
object ObjWithNative {
|
||||
external fun foo(x: Int = 1): Double
|
||||
|
||||
@JvmStatic external fun bar(l: Long, s: String = ""): Double
|
||||
}
|
||||
|
||||
external fun topLevel(x: Int = 1): Double
|
||||
|
||||
fun box(): String {
|
||||
var d = 0.0
|
||||
|
||||
try {
|
||||
d = ObjWithNative.bar(1)
|
||||
return "Link error expected on object"
|
||||
}
|
||||
catch (e: java.lang.UnsatisfiedLinkError) {
|
||||
if (e.message != "foo.ObjWithNative.bar(JLjava/lang/String;)D") return "Fail 1: " + e.message
|
||||
}
|
||||
|
||||
try {
|
||||
d = ObjWithNative.foo()
|
||||
return "Link error expected on object"
|
||||
}
|
||||
catch (e: java.lang.UnsatisfiedLinkError) {
|
||||
if (e.message != "foo.ObjWithNative.foo(I)D") return "Fail 2: " + e.message
|
||||
}
|
||||
|
||||
try {
|
||||
d = topLevel()
|
||||
return "Link error expected on object"
|
||||
}
|
||||
catch (e: java.lang.UnsatisfiedLinkError) {
|
||||
if (e.message != "foo.WithDefaultArgKt.topLevel(I)D") return "Fail 3: " + e.message
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun foo(x: String, block: (String) -> String) = block(x)
|
||||
|
||||
fun box(): String {
|
||||
fun bar(y: String) = y + "cde"
|
||||
|
||||
val res = foo("abc") { bar(it) }
|
||||
|
||||
assertEquals("abccde", res)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun foo(x: String, block: (String) -> String) = block(x)
|
||||
|
||||
fun box(): String {
|
||||
val res = foo("abc") {
|
||||
fun bar(y: String) = y + "cde"
|
||||
bar(it)
|
||||
}
|
||||
|
||||
assertEquals("abccde", res)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun foo(x: String, block: (String) -> String) = block(x)
|
||||
|
||||
fun box(): String {
|
||||
val res = foo("abc") {
|
||||
fun bar(y: String) = y + "cde"
|
||||
foo(it) { bar(it) }
|
||||
}
|
||||
|
||||
assertEquals("abccde", res)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun foo(x: String, block: (String) -> String) = block(x)
|
||||
fun noInlineFoo(x: String, block: (String) -> String) = block(x)
|
||||
|
||||
fun box(): String {
|
||||
val res = foo("abc") {
|
||||
fun bar(y: String) = y + "cde"
|
||||
noInlineFoo(it) { bar(it) }
|
||||
}
|
||||
|
||||
assertEquals("abccde", res)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.jvm.internal.pcollections.HashPMap
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
val map = HashPMap.empty<String, Any>()!!
|
||||
|
||||
assertEquals(0, map.size())
|
||||
|
||||
assertFalse(map.containsKey(""))
|
||||
assertFalse(map.containsKey("abacaba"))
|
||||
assertEquals(null, map[""])
|
||||
assertEquals(null, map["lol"])
|
||||
|
||||
// Check that doesn't create a new map
|
||||
assertEquals(map, map.minus(""))
|
||||
|
||||
// Check that all empty()s are equal
|
||||
val other = HashPMap.empty<String, Any>()!!
|
||||
assertEquals(map, other)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// WITH_REFLECT
|
||||
|
||||
import java.util.*
|
||||
import kotlin.reflect.jvm.internal.pcollections.HashPMap
|
||||
import kotlin.test.*
|
||||
|
||||
fun digitSum(number: Int): Int {
|
||||
var x = number
|
||||
var ans = 0
|
||||
while (x != 0) {
|
||||
ans += x % 10
|
||||
x /= 10
|
||||
}
|
||||
return ans
|
||||
}
|
||||
|
||||
val N = 1000000
|
||||
|
||||
fun box(): String {
|
||||
var map = HashPMap.empty<Int, Any>()!!
|
||||
|
||||
for (x in 1..N) {
|
||||
map = map.plus(x, digitSum(x))!!
|
||||
}
|
||||
|
||||
assertEquals(N, map.size())
|
||||
|
||||
// Check in reverse order just in case
|
||||
for (x in N downTo 1) {
|
||||
assertTrue(map.containsKey(x), "Not found: $x")
|
||||
assertEquals(digitSum(x), map[x], "Incorrect value for $x")
|
||||
}
|
||||
|
||||
// Delete in random order
|
||||
val list = (1..N).toCollection(ArrayList<Int>())
|
||||
Collections.shuffle(list, Random(42))
|
||||
for (x in list) {
|
||||
map = map.minus(x)!!
|
||||
}
|
||||
|
||||
assertEquals(0, map.size())
|
||||
|
||||
for (x in 1..N) {
|
||||
assertFalse(map.containsKey(x), "Incorrectly found: $x")
|
||||
assertEquals(null, map[x], "Incorrectly found value for $x")
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user