Added some tests on local classes in inline bodies

This commit is contained in:
Igor Chevdar
2020-03-26 12:58:40 +03:00
parent e2a378bed7
commit d808ef10b2
11 changed files with 272 additions and 0 deletions
@@ -0,0 +1,31 @@
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND_MULTI_MODULE: JVM, JVM_IR
// FILE: 1.kt
package test
inline fun <T> myRun(block: () -> T) = block()
// FILE: 2.kt
import test.*
interface IFoo {
fun foo(): String
}
class A(val x: String, f: () -> IFoo = {
val y = "K"
myRun {
val o = object: IFoo {
override fun foo() = x + y
}
o
}
}) {
val foo: IFoo = f()
}
fun box(): String {
return A("O").foo.foo()
}
@@ -0,0 +1,24 @@
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND_MULTI_MODULE: JVM, JVM_IR
// FILE: 1.kt
package test
inline fun <T> myRun(block: () -> T) = block()
// FILE: 2.kt
import test.*
fun box(): String {
val y = "O"
val x = myRun {
fun foo() = y + "K"
val o = object {
fun bar() = foo()
}
o
}
return x.bar()
}
@@ -0,0 +1,24 @@
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND_MULTI_MODULE: JVM, JVM_IR
// FILE: 1.kt
package test
inline fun <T> myRun(block: () -> T) = block()
// FILE: 2.kt
import test.*
fun box(): String {
val x = myRun {
fun foo() = "OK"
val o = object {
val f = ::foo
fun bar() = f()
}
o
}
return x.bar()
}
@@ -0,0 +1,29 @@
// FILE: 1.kt
package test
inline fun call(crossinline init: () -> Unit) {
return init()
}
inline fun test(): String {
var res = "Fail"
call {
object {
fun run () {
res = "OK"
}
}.run()
}
return res
}
// FILE: 2.kt
import test.*
fun box(): String {
return test()
}
@@ -0,0 +1,14 @@
// FILE: 1.kt
package test
public inline fun <reified T : Any> foo(block: () -> T) = T::class
// FILE: 2.kt
import test.*
fun box(): String {
foo { object {} }
return "OK"
}