backend/tests: Add blackbox tests from Kotlin JVM
Added tests from testData/codegen/box directory. There are blackbox tests in other directories and they are to be added.
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
interface B<T> {
|
||||
val bar: T
|
||||
}
|
||||
|
||||
fun String.foo() = object : B<String> {
|
||||
override val bar: String = length.toString()
|
||||
}
|
||||
|
||||
class C {
|
||||
|
||||
fun String.extension() = this.length
|
||||
|
||||
fun String.fooInClass() = object : B<String> {
|
||||
override val bar: String = extension().toString()
|
||||
}
|
||||
|
||||
fun String.fooInClassNoReceiver() = object : B<String> {
|
||||
override val bar: String = "123".extension().toString()
|
||||
}
|
||||
|
||||
fun fooInClass(s: String) = s.fooInClass().bar
|
||||
|
||||
fun fooInClassNoReceiver(s: String) = s.fooInClassNoReceiver().bar
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = "Hello, world!".foo().bar
|
||||
if (result != "13") return "fail 1: $result"
|
||||
|
||||
result = C().fooInClass("Hello, world!")
|
||||
|
||||
if (result != "13") return "fail 2: $result"
|
||||
|
||||
result = C().fooInClassNoReceiver("Hello, world!")
|
||||
|
||||
if (result != "3") return "fail 3: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
interface T {
|
||||
fun result(): String
|
||||
}
|
||||
|
||||
class A(val x: String) {
|
||||
fun getx() = x
|
||||
|
||||
fun foo() = object : T {
|
||||
val bar = getx()
|
||||
|
||||
override fun result() = bar
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A("OK").foo().result()
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
interface T {
|
||||
fun result(): String
|
||||
}
|
||||
|
||||
class A(val x: String) {
|
||||
fun foo() = object : T {
|
||||
fun bar() = x
|
||||
|
||||
override fun result() = bar()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A("OK").foo().result()
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
interface T {
|
||||
fun result(): String
|
||||
}
|
||||
|
||||
class A(val x: String) {
|
||||
fun foo() = object : T {
|
||||
val bar = x
|
||||
|
||||
override fun result() = bar
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A("OK").foo().result()
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
interface T {
|
||||
fun result(): String
|
||||
}
|
||||
|
||||
class A(val x: String) {
|
||||
fun foo() = object : T {
|
||||
fun bar() = object : T {
|
||||
fun baz() = object : T {
|
||||
val y = x
|
||||
override fun result() = y
|
||||
}
|
||||
override fun result() = baz().result()
|
||||
}
|
||||
override fun result() = bar().result()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A("OK").foo().result()
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
interface T {
|
||||
fun result(): String
|
||||
}
|
||||
|
||||
open class B(val x: String)
|
||||
|
||||
class A : B("OK") {
|
||||
fun foo() = object : T {
|
||||
val bar = x
|
||||
|
||||
override fun result() = bar
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A().foo().result()
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
interface T {
|
||||
fun result(): String
|
||||
}
|
||||
|
||||
abstract class A<Z>(val x: Z)
|
||||
|
||||
open class B : A<String>("OK")
|
||||
|
||||
class C : B() {
|
||||
fun foo() = object : T {
|
||||
val bar = x
|
||||
|
||||
override fun result() = bar
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = C().foo().result()
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
open class Z(val s: Int) {
|
||||
open fun a() {}
|
||||
}
|
||||
|
||||
class B(val x: Int) {
|
||||
fun foo() {
|
||||
class X : Z(x) {
|
||||
|
||||
}
|
||||
X()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
B(1).foo()
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
//KT-4656 Wrong capturing a function literal variable
|
||||
|
||||
fun box(): String {
|
||||
var foo = { 1 }
|
||||
var bar = 1
|
||||
|
||||
val t = { "${foo()} $bar" }
|
||||
fun b() = "${foo()} $bar"
|
||||
|
||||
foo = { 2 }
|
||||
bar = 2
|
||||
|
||||
if (t() != "2 2") return "fail1"
|
||||
if (b() != "2 2") return "fail2"
|
||||
return "OK"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
fun box() : String {
|
||||
|
||||
fun <T> local(s : T) : T {
|
||||
return s;
|
||||
}
|
||||
|
||||
fun test(s : Int) : Int {
|
||||
return local(s)
|
||||
}
|
||||
|
||||
if (test(10) != 10) return "fail1"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fun box(): String {
|
||||
fun rec(n : Int) {
|
||||
fun x(m : Int) {
|
||||
if (n > 0) rec(n - 1)
|
||||
}
|
||||
|
||||
x(0)
|
||||
}
|
||||
|
||||
rec(5)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fun box(): String {
|
||||
fun rec(n : Int) {
|
||||
fun x(m : Int, k : Int) {
|
||||
if (n > 0) rec(n - 1 + k)
|
||||
}
|
||||
|
||||
x(0, 0)
|
||||
}
|
||||
|
||||
rec(5)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package d
|
||||
|
||||
fun box(): String {
|
||||
ListTag().test(listOf("a", "b"))
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun ListTag.test(list: List<String>) {
|
||||
for (item in list) {
|
||||
item() {
|
||||
a {
|
||||
text = item
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class HtmlTag
|
||||
open class ListTag : HtmlTag() {}
|
||||
class LI : ListTag() {}
|
||||
|
||||
public fun ListTag.item(body: LI.() -> Unit): Unit {}
|
||||
fun HtmlTag.a(contents: A.() -> Unit) {}
|
||||
|
||||
abstract class A : HtmlTag() {
|
||||
public abstract var text: String
|
||||
}
|
||||
|
||||
fun listOf(vararg strings: String): List<String> {
|
||||
val list = ArrayList<String>()
|
||||
for (s in strings) {
|
||||
list.add(s)
|
||||
}
|
||||
return list
|
||||
}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
fun box(): String {
|
||||
fun foo(x: Int) {
|
||||
fun bar(y: Int) {
|
||||
fun baz(z: Int) {
|
||||
foo(x - 1)
|
||||
}
|
||||
|
||||
baz(y)
|
||||
}
|
||||
|
||||
if (x > 0) bar(x)
|
||||
}
|
||||
|
||||
foo(1)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
fun box(): String {
|
||||
fun foo(x: Int, s: String): String {
|
||||
fun bar(y: Int) {
|
||||
fun baz(z: Int, k: Int) {
|
||||
foo(x - 1 + k, "Fail")
|
||||
}
|
||||
|
||||
baz(y, 0)
|
||||
}
|
||||
|
||||
if (x > 0) bar(x)
|
||||
return s
|
||||
}
|
||||
|
||||
return foo(1, "OK")
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
//KT-3276
|
||||
|
||||
fun box(): String {
|
||||
fun rec(n : Int) {
|
||||
val x = { m : Int ->
|
||||
if (n > 0) rec(n - 1)
|
||||
}
|
||||
|
||||
x(0)
|
||||
}
|
||||
|
||||
rec(5)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
//adopted snippet from kdoc
|
||||
open class KModel {
|
||||
val sourcesInfo: String
|
||||
init {
|
||||
fun relativePath(psiFile: String): String {
|
||||
return psiFile;
|
||||
}
|
||||
sourcesInfo = relativePath("OK")
|
||||
}
|
||||
}
|
||||
|
||||
fun box():String {
|
||||
return KModel().sourcesInfo;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
package test
|
||||
|
||||
val p = { "OK" }()
|
||||
|
||||
val getter: String
|
||||
get() = { "OK" }()
|
||||
|
||||
fun f() = { "OK" }()
|
||||
|
||||
val obj = object : Function0<String> {
|
||||
override fun invoke() = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (p != "OK") return "FAIL"
|
||||
if (getter != "OK") return "FAIL"
|
||||
if (f() != "OK") return "FAIL"
|
||||
if (obj() != "OK") return "FAIL"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
val p = { "OK" }()
|
||||
|
||||
val getter: String
|
||||
get() = { "OK" }()
|
||||
|
||||
fun f() = { "OK" }()
|
||||
|
||||
val obj = object : Function0<String> {
|
||||
override fun invoke() = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (p != "OK") return "FAIL"
|
||||
if (getter != "OK") return "FAIL"
|
||||
if (f() != "OK") return "FAIL"
|
||||
if (obj() != "OK") return "FAIL"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun box() : String {
|
||||
return apply( "OK", {arg: String -> arg } )
|
||||
}
|
||||
|
||||
fun apply(arg : String, f : (p:String) -> String) : String {
|
||||
return f(arg)
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun box() : String {
|
||||
return if (apply( 5, {arg: Int -> arg + 13 } ) == 18) "OK" else "fail"
|
||||
}
|
||||
|
||||
fun apply(arg : Int, f : (p:Int) -> Int) : Int {
|
||||
return f(arg)
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun box() : String {
|
||||
val cl = 39
|
||||
return if (sum(200, { val ff = {cl}; ff() }) == 239) "OK" else "FAIL"
|
||||
}
|
||||
|
||||
fun sum(arg:Int, f : () -> Int) : Int {
|
||||
return arg + f()
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun box() : String {
|
||||
val cl = 39
|
||||
return if (sum(200, { val m = { val r = { cl }; r() }; m() }) == 239) "OK" else "FAIL"
|
||||
}
|
||||
|
||||
fun sum(arg:Int, f : () -> Int) : Int {
|
||||
return arg + f()
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class Point(val x:Int, val y:Int) {
|
||||
fun mul() : (scalar:Int)->Point {
|
||||
return { scalar:Int -> Point(x * scalar, y * scalar) }
|
||||
}
|
||||
}
|
||||
|
||||
val m = Point(2, 3).mul()
|
||||
|
||||
fun box() : String {
|
||||
val answer = m(5)
|
||||
return if (answer.x == 10 && answer.y == 15) "OK" else "FAIL"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class Point(val x : Int, val y : Int)
|
||||
|
||||
fun box() : String {
|
||||
val answer = apply(Point(3, 5), { scalar : Int ->
|
||||
Point(x * scalar, y * scalar)
|
||||
})
|
||||
|
||||
return if (answer.x == 6 && answer.y == 10) "OK" else "FAIL"
|
||||
}
|
||||
|
||||
fun apply(arg:Point, f : Point.(scalar : Int) -> Point) : Point {
|
||||
return arg.f(2)
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
open class JClass() {
|
||||
fun test(): String {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
class Example : JClass {
|
||||
constructor() : super()
|
||||
|
||||
private var obj: JClass? = null
|
||||
|
||||
var result: String? = null
|
||||
|
||||
init {
|
||||
{
|
||||
result = obj?.test()
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
class Example2 : JClass {
|
||||
constructor() : super()
|
||||
|
||||
private var obj: JClass? = this
|
||||
|
||||
var result: String? = null
|
||||
|
||||
init {
|
||||
{
|
||||
result = obj?.test()
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val result = Example().result
|
||||
if (result != null) "fail 1: $result"
|
||||
|
||||
return Example2().result!!
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
interface A {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
class AImpl(val z: String) : A {
|
||||
override fun foo(): String = z
|
||||
}
|
||||
|
||||
open class AFabric {
|
||||
open fun createA(): A = AImpl("OK")
|
||||
}
|
||||
|
||||
class AWrapperFabric : AFabric() {
|
||||
|
||||
override fun createA(): A {
|
||||
return AImpl("fail")
|
||||
}
|
||||
|
||||
fun createMyA(): A {
|
||||
return object : A by super.createA() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return AWrapperFabric().createMyA().foo()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
interface A {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
class AImpl(val z: String) : A {
|
||||
override fun foo(): String = z
|
||||
}
|
||||
|
||||
open class AFabric {
|
||||
open fun createA(z: String): A = AImpl(z)
|
||||
}
|
||||
|
||||
class AWrapperFabric : AFabric() {
|
||||
|
||||
override fun createA(z: String): A {
|
||||
return AImpl("fail: $z")
|
||||
}
|
||||
|
||||
fun createMyA(): A {
|
||||
val z = "OK"
|
||||
return object : A by super.createA(z) {}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return AWrapperFabric().createMyA().foo()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
interface A {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
class AImpl(val z: String) : A {
|
||||
override fun foo(): String = z
|
||||
}
|
||||
|
||||
open class AFabric {
|
||||
open fun createA(z: String): A = AImpl(z)
|
||||
}
|
||||
|
||||
class AWrapperFabric : AFabric() {
|
||||
|
||||
override fun createA(z: String): A {
|
||||
return AImpl("fail: $z")
|
||||
}
|
||||
|
||||
fun createMyA(): A {
|
||||
val z = "OK"
|
||||
return object : A by super<AFabric>@AWrapperFabric.createA(z) {}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return AWrapperFabric().createMyA().foo()
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
interface A {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
open class Base (val p: String) {
|
||||
open val a = object : A {
|
||||
override fun foo(): String {
|
||||
return p
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open class Derived1 (p: String): Base(p) {
|
||||
override open val a = object : A {
|
||||
override fun foo(): String {
|
||||
return "fail"
|
||||
}
|
||||
}
|
||||
|
||||
inner class Derived2(p: String) : Base(p) {
|
||||
val x = object : A by super<Base>@Derived1.a {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return Derived1("OK").Derived2("fail").x.foo()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fun foo(): String {
|
||||
return if (true) {
|
||||
var x = "OK"
|
||||
fun foo() { x += "fail" }
|
||||
x
|
||||
} else "fail"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return foo()
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
public class Test {
|
||||
val content = 1
|
||||
inner class A {
|
||||
val v = object {
|
||||
fun f() = content
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
Test().A()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
open class Base {
|
||||
fun doSomething() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class X(val action: () -> Unit) { }
|
||||
|
||||
class Foo : Base() {
|
||||
inner class Bar() {
|
||||
val x = X({ doSomething() })
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
Foo().Bar()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
class A {
|
||||
fun foo() {}
|
||||
fun bar(f: A.() -> Unit = {}) {}
|
||||
}
|
||||
|
||||
class B {
|
||||
class D {
|
||||
init {
|
||||
A().bar {
|
||||
this.foo()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
B.D()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun box() : String {
|
||||
fun <T> foo(t:() -> T) : T = t()
|
||||
|
||||
return foo {"OK"}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
class Foo(private val s: String) {
|
||||
inner class Inner {
|
||||
private val x = {
|
||||
this@Foo.s
|
||||
}()
|
||||
}
|
||||
|
||||
val f = Inner()
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
Foo("!")
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
open class A(val s: Int) {
|
||||
|
||||
}
|
||||
|
||||
infix fun Int.foo(s: Int): Int {
|
||||
return this + s
|
||||
}
|
||||
|
||||
open class B : A({ 1 foo 2} ())
|
||||
|
||||
fun box(): String {
|
||||
return if (B().s == 3) "OK" else "Fail"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun box(): String {
|
||||
val x = "OK"
|
||||
fun bar(y: String = x): String = y
|
||||
return bar()
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun box(): String {
|
||||
val o = "O"
|
||||
fun ok() = o + "K"
|
||||
class OK {
|
||||
val ok = ok()
|
||||
}
|
||||
return OK().ok
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun box(): String {
|
||||
val o = "O"
|
||||
val ok_L = {o + "K"}
|
||||
class OK {
|
||||
val ok = ok_L()
|
||||
}
|
||||
return OK().ok
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
fun box(): String {
|
||||
|
||||
fun local():Int {
|
||||
return 10;
|
||||
}
|
||||
|
||||
class A {
|
||||
fun test(): Int {
|
||||
return local()
|
||||
}
|
||||
}
|
||||
|
||||
return if (A().test() == 10) "OK" else "fail"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fun box(): String {
|
||||
|
||||
fun local():Int {
|
||||
return 10;
|
||||
}
|
||||
|
||||
class A {
|
||||
val test = local()
|
||||
}
|
||||
|
||||
return if (A().test == 10) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fun box() : String {
|
||||
|
||||
fun <T> local(s : T) : T {
|
||||
return s;
|
||||
}
|
||||
|
||||
if (local(10) != 10) return "fail1"
|
||||
|
||||
if (local("11") != "11") return "fail2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
fun box(): String {
|
||||
val a = 1
|
||||
val explicitlyReturned = run1 f@{
|
||||
if (a > 0)
|
||||
return@f "OK"
|
||||
else "Fail 1"
|
||||
}
|
||||
if (explicitlyReturned != "OK") return explicitlyReturned
|
||||
|
||||
val implicitlyReturned = run1 f@{
|
||||
if (a < 0)
|
||||
return@f "Fail 2"
|
||||
else "OK"
|
||||
}
|
||||
if (implicitlyReturned != "OK") return implicitlyReturned
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun <T> run1(f: () -> T): T { return f() }
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
fun box(): String {
|
||||
val a = 1
|
||||
val explicitlyReturned = run1 {
|
||||
if (a > 0)
|
||||
return@run1 "OK"
|
||||
else "Fail 1"
|
||||
}
|
||||
if (explicitlyReturned != "OK") return explicitlyReturned
|
||||
|
||||
val implicitlyReturned = run1 {
|
||||
if (a < 0)
|
||||
return@run1 "Fail 2"
|
||||
else "OK"
|
||||
}
|
||||
if (implicitlyReturned != "OK") return implicitlyReturned
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun <T> run1(f: () -> T): T { return f() }
|
||||
@@ -0,0 +1,22 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
// WITH_RUNTIME
|
||||
|
||||
class A {
|
||||
fun f(): () -> String {
|
||||
val s = "OK"
|
||||
return { -> s }
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val lambdaClass = A().f().javaClass
|
||||
val fields = lambdaClass.getDeclaredFields().toList()
|
||||
if (fields.size != 1) return "Fail: lambda should only capture 's': $fields"
|
||||
|
||||
val fieldName = fields[0].getName()
|
||||
if (fieldName != "\$s") return "Fail: captured variable should be named '\$s': $fields"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(s: String): String {
|
||||
fun bar(count: Int): String =
|
||||
if (count == 0) s else bar(count - 1)
|
||||
return bar(10)
|
||||
}
|
||||
|
||||
fun box(): String = foo("OK")
|
||||
@@ -0,0 +1,7 @@
|
||||
fun box() : String {
|
||||
return invoker( {"OK"} )
|
||||
}
|
||||
|
||||
fun invoker(gen : () -> String) : String {
|
||||
return gen()
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun box() : String {
|
||||
return if (int_invoker( { 7 } ) == 7) "OK" else "fail"
|
||||
}
|
||||
|
||||
fun int_invoker(gen : () -> Int) : Int {
|
||||
return gen()
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
fun <R> run(block: () -> R) = block()
|
||||
inline fun <R> inlineRun(block: () -> R) = block()
|
||||
|
||||
class Outer(val outerProp: String) {
|
||||
fun foo(arg: String): String {
|
||||
class Local {
|
||||
val work1 = run { outerProp + arg }
|
||||
val work2 = inlineRun { outerProp + arg }
|
||||
val obj = object : Any() {
|
||||
override fun toString() = outerProp + arg
|
||||
}
|
||||
|
||||
override fun toString() = "${work1}#${work2}#${obj.toString()}"
|
||||
}
|
||||
|
||||
return Local().toString()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val res = Outer("O").foo("K")
|
||||
if (res != "OK#OK#OK") return "fail: $res"
|
||||
return "OK"
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun foo(block: (String, String, String) -> String): String = block("O", "fail", "K")
|
||||
|
||||
fun box() = foo { x, _, y -> x + y }
|
||||
Reference in New Issue
Block a user