tests: Update external tests (1.1.2-dev-393)

This commit is contained in:
Ilya Matveev
2017-03-13 12:38:08 +03:00
committed by ilmat192
parent ac56fccb15
commit bc074e6d39
3178 changed files with 22396 additions and 696 deletions
@@ -0,0 +1,22 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun <reified R> foo() = bar<R>() {"OK"}
inline fun <reified E> bar(crossinline y: () -> String) = {
null is E
run(y)
}
public inline fun <T> call(f: () -> T): T = f()
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
val x: () -> String = foo<String>()
fun box(): String {
return x()
}
@@ -0,0 +1,22 @@
// IGNORE_BACKEND: NATIVE
// FILE: 1.kt
// WITH_REFLECT
package test
inline fun <reified R, T> bar(crossinline tasksFactory: () -> T) = {
null is R
run(tasksFactory)
}
public inline fun <T> call(f: () -> T): T = f()
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
inline fun <reified R> foo() = bar<R, String>() {"OK"}
fun box(): String {
return foo<String>()()
}
@@ -0,0 +1,51 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
class A
class B
inline fun <reified T> Any?.foo(): T = this as T
inline fun <reified Y> Any?.foo2(): Y? = foo<Y?>()
inline fun <reified Z> Any?.foo3(): Z? = foo2<Z>()
// FILE: 2.kt
import test.*
fun box(): String {
if (null.foo3<Any>() != null) return "fail 1"
if (null.foo3<Any?>() != null) return "fail 2"
if (null.foo3<A>() != null) return "fail 3"
if (null.foo3<A?>() != null) return "fail 4"
val a = A()
if (a.foo3<Any>() != a) return "fail 5"
if (a.foo3<Any?>() != a) return "fail 6"
if (a.foo3<A>() != a) return "fail 7"
if (a.foo3<A?>() != a) return "fail 8"
val b = B()
failClassCast { b.foo3<A>(); return "failTypeCast 9" }
failClassCast { b.foo3<A?>(); return "failTypeCast 10" }
return "OK"
}
inline fun failClassCast(s: () -> Unit) {
try {
s()
}
catch (e: TypeCastException) {
throw e
}
catch (e: ClassCastException) {
}
}
@@ -0,0 +1,26 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun <reified T, reified R>T.castTo(): R = this as R
// FILE: 2.kt
import test.*
fun case1(): Int =
null.castTo<Int?, Int>()
fun box(): String {
failTypeCast { case1(); return "failTypeCast 9" }
return "OK"
}
inline fun failTypeCast(s: () -> Unit) {
try {
s()
}
catch (e: TypeCastException) {
}
}
@@ -0,0 +1,27 @@
// FILE: 1.kt
package test
class A
fun call(a: String, b: String, c: String, d: String, e: String, f: Any) {
}
inline fun <reified T: Any> Any?.foo(): T {
call("1", "2", "3", "4", "5", this as T)
return this as T
}
// FILE: 2.kt
import test.*
fun box(): String {
val a = A()
if (a.foo<Any>() != a) return "failTypeCast 5"
return "OK"
}
@@ -0,0 +1,56 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
class A
class B
inline fun <reified T> Any?.foo(): T? = this as T?
// FILE: 2.kt
import test.*
fun box(): String {
if (null.foo<Any>() != null) return "failTypeCast 1"
if (null.foo<Any?>() != null) return "failTypeCast 2"
if (null.foo<A>() != null) return "failTypeCast 3"
if (null.foo<A?>() != null) return "failTypeCast 4"
val a = A()
if (a.foo<Any>() != a) return "failTypeCast 5"
if (a.foo<Any?>() != a) return "failTypeCast 6"
if (a.foo<A>() != a) return "failTypeCast 7"
if (a.foo<A?>() != a) return "failTypeCast 8"
val b = B()
failClassCast { b.foo<A>(); return "failTypeCast 9" }
failClassCast { b.foo<A?>(); return "failTypeCast 10" }
return "OK"
}
inline fun failTypeCast(s: () -> Unit) {
try {
s()
}
catch (e: TypeCastException) {
}
}
inline fun failClassCast(s: () -> Unit) {
try {
s()
}
catch (e: TypeCastException) {
throw e
}
catch (e: ClassCastException) {
}
}
@@ -0,0 +1,56 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
class A
class B
inline fun <reified T> Any?.foo(): T = this as T
// FILE: 2.kt
import test.*
fun box(): String {
failTypeCast { null.foo<Any>(); return "failTypeCast 1" }
if (null.foo<Any?>() != null) return "failTypeCast 2"
failTypeCast { null.foo<A>(); return "failTypeCast 3" }
if (null.foo<A?>() != null) return "failTypeCast 4"
val a = A()
if (a.foo<Any>() != a) return "failTypeCast 5"
if (a.foo<Any?>() != a) return "failTypeCast 6"
if (a.foo<A>() != a) return "failTypeCast 7"
if (a.foo<A?>() != a) return "failTypeCast 8"
val b = B()
failClassCast { b.foo<A>(); return "failTypeCast 9" }
failClassCast { b.foo<A?>(); return "failTypeCast 10" }
return "OK"
}
inline fun failTypeCast(s: () -> Unit) {
try {
s()
}
catch (e: TypeCastException) {
}
}
inline fun failClassCast(s: () -> Unit) {
try {
s()
}
catch (e: TypeCastException) {
throw e
}
catch (e: ClassCastException) {
}
}
@@ -0,0 +1,56 @@
// FILE: 1.kt
// WITH_RUNTIME
package test
class A
class B
inline fun <reified T> Any?.foo(): T? = this as? T
// FILE: 2.kt
import test.*
fun box(): String {
if (null.foo<Any>() != null) return "failTypeCast 1"
if (null.foo<Any?>() != null) return "failTypeCast 2"
if (null.foo<A>() != null) return "failTypeCast 3"
if (null.foo<A?>() != null) return "failTypeCast 4"
val a = A()
if (a.foo<Any>() != a) return "failTypeCast 5"
if (a.foo<Any?>() != a) return "failTypeCast 6"
if (a.foo<A>() != a) return "failTypeCast 7"
if (a.foo<A?>() != a) return "failTypeCast 8"
val b = B()
if (b.foo<A>() != null) return "fail 9"
if (b.foo<A?>() != null) return "fail 10"
return "OK"
}
inline fun failTypeCast(s: () -> Unit) {
try {
s()
}
catch (e: TypeCastException) {
}
}
inline fun failClassCast(s: () -> Unit) {
try {
s()
}
catch (e: TypeCastException) {
throw e
}
catch (e: ClassCastException) {
}
}
@@ -0,0 +1,39 @@
// FILE: 1.kt
package test
class A
class B
inline fun <reified T> Any?.foo() = this is T
inline fun <reified Y> Any?.foo2() = foo<Y?>()
inline fun <reified Z> Any?.foo3() = foo2<Z>()
// FILE: 2.kt
import test.*
fun box(): String {
if (null.foo3<Any>() != true) return "fail 1"
if (null.foo3<Any?>() != true) return "fail 2"
if (null.foo3<A>() != true) return "fail 3"
if (null.foo3<A?>() != true) return "fail 4"
val a = A()
if (a.foo3<Any>() != true) return "fail 5"
if (a.foo3<Any?>() != true) return "fail 6"
if (a.foo3<A>() != true) return "fail 7"
if (a.foo3<A?>() != true) return "fail 8"
val b = B()
if (b.foo3<A>() != false) return "fail 9"
if (b.foo3<A?>() != false) return "fail 10"
return "OK"
}
@@ -0,0 +1,35 @@
// FILE: 1.kt
package test
class A
class B
inline fun <reified T> Any?.foo() = this is T?
// FILE: 2.kt
import test.*
fun box(): String {
if (null.foo<Any>() != true) return "fail 1"
if (null.foo<Any?>() != true) return "fail 2"
if (null.foo<A>() != true) return "fail 3"
if (null.foo<A?>() != true) return "fail 4"
val a = A()
if (a.foo<Any>() != true) return "fail 5"
if (a.foo<Any?>() != true) return "fail 6"
if (a.foo<A>() != true) return "fail 7"
if (a.foo<A?>() != true) return "fail 8"
val b = B()
if (b.foo<A>() != false) return "fail 9"
if (b.foo<A?>() != false) return "fail 10"
return "OK"
}
@@ -0,0 +1,35 @@
// FILE: 1.kt
package test
class A
class B
inline fun <reified T> Any?.foo() = this is T
// FILE: 2.kt
import test.*
fun box(): String {
if (null.foo<Any>() != false) return "fail 1"
if (null.foo<Any?>() != true) return "fail 2"
if (null.foo<A>() != false) return "fail 3"
if (null.foo<A?>() != true) return "fail 4"
val a = A()
if (a.foo<Any>() != true) return "fail 5"
if (a.foo<Any?>() != true) return "fail 6"
if (a.foo<A>() != true) return "fail 7"
if (a.foo<A?>() != true) return "fail 8"
val b = B()
if (b.foo<A>() != false) return "fail 9"
if (b.foo<A?>() != false) return "fail 10"
return "OK"
}
@@ -0,0 +1,44 @@
// IGNORE_BACKEND: NATIVE
// FILE: 1.kt
// WITH_REFLECT
package test
open class TypeRef<T> {
val type = target()
private fun target(): String {
val thisClass = this.javaClass
val superClass = thisClass.genericSuperclass
return superClass.toString()
}
}
inline fun <reified T> typeWithMessage(message: String = "Hello"): String {
val type = object : TypeRef<T>() {}
val target = type.type
return message + " " + target
}
// FILE: 2.kt
import test.*
fun specifyOptionalArgument() = typeWithMessage<List<Int>>("Hello")
fun useDefault() = typeWithMessage<List<Int>>()
fun box(): String {
val specifyOptionalArgument = specifyOptionalArgument()
val useDefault = useDefault()
if (useDefault != specifyOptionalArgument) return "fail: $useDefault != $specifyOptionalArgument"
val type = typeWithMessage<List<Int>>("")
if (type != " test.TypeRef<java.util.List<? extends java.lang.Integer>>") return "fail 2: $type"
return "OK"
}
@@ -0,0 +1,34 @@
// IGNORE_BACKEND: NATIVE
// FILE: 1.kt
// FULL_JDK
// WITH_REFLECT
package test
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
open class TypeLiteral<T> {
val type: Type
get() = (javaClass.genericSuperclass as ParameterizedType).getActualTypeArguments()[0]
}
// normal inline function works fine
inline fun <reified T> typeLiteral(): TypeLiteral<T> = object : TypeLiteral<T>() {}
// nested lambda loses reification of T
inline fun <reified T> brokenTypeLiteral(): TypeLiteral<T> = "".run { typeLiteral<T>() }
// FILE: 2.kt
import test.*
fun box(): String {
val type1 = typeLiteral<List<String>>().type.toString()
if (type1 != "java.util.List<? extends java.lang.String>") return "fail 1: $type1"
val type2 = brokenTypeLiteral<List<String>>().type.toString()
if (type2 != "java.util.List<? extends java.lang.String>") return "fail 2: $type2"
return "OK"
}
@@ -0,0 +1,27 @@
// IGNORE_BACKEND: NATIVE
// FILE: 1.kt
// WITH_REFLECT
package test
interface Call<T> {
fun call(): T
}
public inline fun <reified T: Any> Any.inlineMeIfYouCan() : () -> Call<T> = {
object : Call<T> {
override fun call() = T::class.java.newInstance()
}
}
// FILE: 2.kt
import test.*
public class A()
fun box(): String {
val s = "yo".inlineMeIfYouCan<A>()().call()
if (s !is A) return "fail"
return "OK"
}
@@ -0,0 +1,22 @@
// IGNORE_BACKEND: NATIVE
// FILE: 1.kt
// WITH_REFLECT
package test
public inline fun <reified T: Any> Any.inlineMeIfYouCan() : () -> Runnable = {
object : Runnable {
override fun run() {
T::class.java.newInstance()
}
}
}
// FILE: 2.kt
import test.*
fun box(): String {
"yo".inlineMeIfYouCan<StringBuilder>()().run()
return "OK"
}
@@ -0,0 +1,23 @@
// IGNORE_BACKEND: NATIVE
// FILE: 1.kt
// WITH_REFLECT
package test
public inline fun <reified T : Any> inlineMeIfYouCan(): String? =
{
f {
T::class.java.getName()
}
}()
inline fun f(x: () -> String) = x()
// FILE: 2.kt
import test.*
class OK
fun box(): String {
return inlineMeIfYouCan<OK>()!!
}
@@ -0,0 +1,23 @@
// FILE: 1.kt
package test
inline fun <reified T> test(x: Any): Boolean {
val x = object {
val y = x is T
}
return x.y
}
// FILE: 2.kt
import test.*
fun box(): String {
if (!test<String>("OK")) return "fail 1"
if (test<Int>("OK")) return "fail 2"
return "OK"
}
@@ -0,0 +1,16 @@
// FILE: 1.kt
package test
inline fun <reified T> f(x : () -> Unit) {
object { init { arrayOf<T>() } }
}
// FILE: 2.kt
import test.*
fun box(): String {
f<String>() {}
return "OK"
}
@@ -0,0 +1,37 @@
// IGNORE_BACKEND: NATIVE
// FILE: 1.kt
// WITH_REFLECT
package test
import java.util.*
import kotlin.reflect.KClass
val valuesInjectFnc = HashMap<KClass<out Any>, Any>()
inline fun <reified T : Any> injectFnc(): Lazy<Function0<T>> = lazy(LazyThreadSafetyMode.NONE) {
(valuesInjectFnc[T::class] ?: throw Exception("no inject ${T::class.simpleName}")) as Function0<T>
}
inline fun <reified T : Any> registerFnc(noinline value: Function0<T>) {
valuesInjectFnc[T::class] = value
}
public class Box
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
class Boxer {
val box: () -> Box by injectFnc()
}
fun box(): String {
val box = Box()
registerFnc { box }
val prop = Boxer().box
if (prop() != box) return "fail 1"
return "OK"
}
@@ -0,0 +1,22 @@
// FILE: 1.kt
package test
import kotlin.reflect.KClass
inline fun <reified T : Any> injectFnc(): KClass<T> = {
T::class
} ()
public class Box
// FILE: 2.kt
import test.*
fun box(): String {
val boxClass = injectFnc<Box>()
if (boxClass != Box::class) return "fail 1"
return "OK"
}
@@ -0,0 +1,40 @@
// IGNORE_BACKEND: NATIVE
// FILE: 1.kt
// WITH_REFLECT
package test
public abstract class A<T>
inline fun <reified T> foo1(): A<T> {
return object : A<T>() {
}
}
fun<T> bar(x: T, block: (T) -> Boolean): Boolean = block(x)
inline fun <reified T> foo2(x: Any): Boolean {
return bar(x) { it is T }
}
inline fun <reified T> foo3(x: Any, y: Any): Boolean {
return bar(x) { it is T && y is T }
}
// FILE: 2.kt
//NO_CHECK_LAMBDA_INLINING
import test.*
fun box(): String {
val x = foo1<Int>().javaClass.getGenericSuperclass()?.toString()
if (x != "test.A<java.lang.Integer>") return "fail 1: " + x
if (!foo2<String>("abc")) return "fail 2"
if (foo2<Int>("abc")) return "fail 3"
if (!foo3<String>("abc", "cde")) return "fail 4"
if (foo3<String>("abc", 1)) return "fail 5"
return "OK"
}