Add test for Obsolete issues

#KT-15956 Obsolete
 #KT-15751 Obsolete
 #KT-16417 Obsolete
 #KT-21787 Obsolete
This commit is contained in:
Mikhael Bogdanov
2019-01-08 10:00:08 +01:00
parent 6a19e45e27
commit 9a059809bf
17 changed files with 262 additions and 0 deletions
@@ -0,0 +1,22 @@
// WITH_RUNTIME
class Container {
var id: Int? = null
}
class TestClass {
private fun createContainer(id: Int): Container { val q = Container(); q.id = id; return q }
fun createContainers1(from: Int = 0, to: Int = 100) = (from .. to).map(::createContainer)
fun createContainers2(from: Int = 0, to: Int = 100): List<Container> { return (from .. to).map(::createContainer) }
}
fun box(): String {
val testClass = TestClass()
val containers1 = testClass.createContainers1().size
if (containers1 != 101) return "fail 1: $containers1"
val containers2 = testClass.createContainers2().size
if (containers2 != 101) return "fail 2: $containers2"
return "OK"
}
@@ -0,0 +1,32 @@
// FILE: 1.kt
// NO_CHECK_LAMBDA_INLINING
class A {
val foo = fun(call: () -> Unit) =
ext {
fun send() {
call()
}
bar {
send()
}
}
fun bar(body: () -> Unit) {
body()
}
inline fun A.ext(init: X.() -> Unit) {
return X().init()
}
class X
}
// FILE: 2.kt
fun box(): String {
var result = "fail"
A().foo { result = "OK" }
return result
}
@@ -0,0 +1,34 @@
// FILE: 1.kt
// IGNORE_BACKEND: JS
// WITH_RUNTIME
public inline fun <T> T.myalso(block: (T) -> Unit): T {
block(this)
return this
}
public inline fun <T, R : Any> Iterable<T>.mymapNotNull(transform: (T) -> R?): List<R> {
return mapNotNullTo(ArrayList<R>(), transform)
}
// FILE: 2.kt
// NO_CHECK_LAMBDA_INLINING
var result = -1;
fun box(): String {
fff()
return if (result == 1) "OK" else "fail $result"
}
fun fff(): Int {
val y = 0
return 0.myalso {
fun increase(x: Int): Int = x + y
val values = listOf(1).mymapNotNull { something(::increase, it) }
result = values[0]!!
}
}
fun something(increase: (Int) -> Int, x: Int): Int? {
return increase(x)
}
@@ -0,0 +1,45 @@
// IGNORE_BACKEND: JVM_IR
// FILE: 1.kt
class A {
var field = 0
inline fun a(f: () -> Any): Any {
try {
val value = f()
return value
} finally {
field--
}
}
private inline fun b(rule: () -> Unit) {
try {
rule()
} catch (fail: Throwable) {}
}
fun c(vararg functions: () -> Any): Any = a {
for (function in functions) {
b { return function() }
}
throw RuntimeException()
}
}
// FILE: 2.kt
// NO_CHECK_LAMBDA_INLINING
fun box(): String {
val a = A()
a.c ({ "OK" })
if (a.field != -1) return "fail 1: ${a.field}"
try {
a.c({ null!! })
} catch (e: RuntimeException) {
// OK
} catch (e: Throwable) {
return "fail 2: $e"
}
return a.c ({ "OK" }) as String
}
+24
View File
@@ -0,0 +1,24 @@
// FILE: 1.kt
// WITH_REFLECT
// IGNORE_BACKEND: JVM_IR
package foo
import kotlin.reflect.full.primaryConstructor
inline fun <reified T : Any> f(): String {
var result = ""
for (p in T::class.primaryConstructor!!.parameters.sortedBy { it.index }) {
result += p.name
}
return result
}
// FILE: 2.kt
import foo.*
class A(val O: Int, val K: Int)
fun box(): String {
return f<A>()
}