tests: Update external tests (1.1.2-dev-393)
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
fun a(): IntArray? = null
|
||||
|
||||
fun b(): Nothing = throw Exception()
|
||||
|
||||
fun foo(): IntArray = a() ?: b()
|
||||
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Exception) {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
return "Fail"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fun a(): String? = null
|
||||
|
||||
fun b(): Nothing = throw Exception()
|
||||
|
||||
fun foo(): String = a() ?: b()
|
||||
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
foo()
|
||||
} catch (e: Exception) {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
return "Fail"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// TODO: Enable when JS backend gets support of Java class library
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
fun ok(b: Boolean) = if (b) "OK" else "Fail"
|
||||
|
||||
fun box(): String {
|
||||
val data = java.util.Arrays.asList("foo", "bar")!!
|
||||
return ok(data.contains("foo"))
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
open abstract class B {
|
||||
fun foo(arg: Int = 239 + 1) : Int = arg
|
||||
}
|
||||
|
||||
class C() : B() {
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if(C().foo(10) != 10) return "fail"
|
||||
if(C().foo() != 240) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun <T> T.toPrefixedString(prefix: String = "", suffix: String="") = prefix + this.toString() + suffix
|
||||
|
||||
fun box() : String {
|
||||
if("mama".toPrefixedString(suffix="321", prefix="papa") != "papamama321") return "fail"
|
||||
if("mama".toPrefixedString(prefix="papa") != "papamama") return "fail"
|
||||
if("mama".toPrefixedString("papa", "239") != "papamama239") return "fail"
|
||||
if("mama".toPrefixedString("papa") != "papamama") return "fail"
|
||||
if("mama".toPrefixedString() != "mama") return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
class T4(
|
||||
val c1: Boolean,
|
||||
val c2: Boolean,
|
||||
val c3: Boolean,
|
||||
val c4: String
|
||||
) {
|
||||
override fun equals(o: Any?): Boolean {
|
||||
if (o !is T4) return false;
|
||||
return c1 == o.c1 &&
|
||||
c2 == o.c2 &&
|
||||
c3 == o.c3 &&
|
||||
c4 == o.c4
|
||||
}
|
||||
}
|
||||
|
||||
fun reformat(
|
||||
str : String,
|
||||
normalizeCase : Boolean = true,
|
||||
uppercaseFirstLetter : Boolean = true,
|
||||
divideByCamelHumps : Boolean = true,
|
||||
wordSeparator : String = " "
|
||||
) =
|
||||
T4(normalizeCase, uppercaseFirstLetter, divideByCamelHumps, wordSeparator)
|
||||
|
||||
|
||||
fun box() : String {
|
||||
val expected = T4(true, true, true, " ")
|
||||
if(reformat("", true, true, true, " ") != expected) return "fail"
|
||||
if(reformat("", true, true, true) != expected) return "fail"
|
||||
if(reformat("", true, true) != expected) return "fail"
|
||||
if(reformat("", true) != expected) return "fail"
|
||||
if(reformat("") != expected) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
class C() {
|
||||
fun Any.toMyPrefixedString(prefix: String = "", suffix: String="") : String = prefix + " " + suffix
|
||||
|
||||
fun testReceiver() : String {
|
||||
val res : String = "mama".toMyPrefixedString("111", "222")
|
||||
return res
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if(C().testReceiver() != "111 222") return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
interface A {
|
||||
fun bar2(arg: Int = 239) : Int
|
||||
|
||||
fun bar(arg: Int = 240) : Int = bar2(arg/2)
|
||||
}
|
||||
|
||||
open abstract class B : A {
|
||||
override fun bar2(arg: Int) : Int = arg
|
||||
}
|
||||
|
||||
class C : B()
|
||||
|
||||
fun box() : String {
|
||||
if(C().bar(10) != 5) return "fail"
|
||||
if(C().bar() != 120) return "fail"
|
||||
if(C().bar2() != 239) return "fail"
|
||||
if(C().bar2(10) != 10) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
open abstract class B {
|
||||
abstract fun foo2(arg: Int = 239) : Int
|
||||
}
|
||||
|
||||
class C : B() {
|
||||
override fun foo2(arg: Int) : Int = arg
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if(C().foo2() != 239) return "fail"
|
||||
if(C().foo2(10) != 10) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
interface A {
|
||||
fun foo(x: Int, y: Int = x + 20, z: Int = y * 2) = z
|
||||
}
|
||||
|
||||
class B : A {}
|
||||
|
||||
fun box() = if (B().foo(1) == 42) "OK" else "Fail"
|
||||
@@ -0,0 +1,5 @@
|
||||
class A(val expected: Int) {
|
||||
fun foo(x: Int, y: Int = x + 20, z: Int = y * 2) = z == expected
|
||||
}
|
||||
|
||||
fun box() = if (A(42).foo(1)) "OK" else "Fail"
|
||||
@@ -0,0 +1,7 @@
|
||||
fun box(): String {
|
||||
return justPrint(9.compareTo(4))
|
||||
}
|
||||
|
||||
fun justPrint(value: Int): String {
|
||||
return if (value > 0) "OK" else "Fail $value"
|
||||
}
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
interface Named {
|
||||
abstract fun getName() : String;
|
||||
}
|
||||
|
||||
interface MemberDescriptor : Named {}
|
||||
|
||||
interface ClassifierDescriptor : Named {}
|
||||
|
||||
interface ClassDescriptor : MemberDescriptor, ClassifierDescriptor {}
|
||||
|
||||
class ClassDescriptorImpl : ClassDescriptor {
|
||||
override fun getName(): String {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
class A(val descriptor : ClassDescriptor) {
|
||||
val result : String = descriptor.getName()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return A(ClassDescriptorImpl()).result
|
||||
}
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
val foo1 = fun Any.(): String {
|
||||
return "239" + this
|
||||
}
|
||||
|
||||
val foo2 = fun Int.(i : Int) : Int = this + i
|
||||
|
||||
fun <T> fooT1() = fun (t : T) = t.toString()
|
||||
|
||||
annotation class A
|
||||
|
||||
fun box() : String {
|
||||
if(10.foo1() != "23910") return "foo1 fail"
|
||||
if(10.foo2(1) != 11) return "foo2 fail"
|
||||
|
||||
if(1.(fun Int.() = this + 1)() != 2) return "test 3 failed";
|
||||
if( (fun () = 1)() != 1) return "test 4 failed";
|
||||
if( (fun (i: Int) = i)(1) != 1) return "test 5 failed";
|
||||
if( 1.(fun Int.(i: Int) = i + this)(1) != 2) return "test 6 failed";
|
||||
if( (fooT1<String>()("mama")) != "mama") return "test 7 failed";
|
||||
|
||||
val a = @A fun Int.() = this + 1
|
||||
if (1.a() != 2) return "test 8 failed"
|
||||
val b = ( fun Int.() = this + 1)
|
||||
if (1.b() != 2) return "test 9 failed"
|
||||
val c = (c@ fun Int.() = this + 1)
|
||||
if (1.c() != 2) return "test 10 failed"
|
||||
|
||||
val d = d@ fun (): Int { return@d 4}
|
||||
if (d() != 4) return "test 11 failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
|
||||
fun Int.thisRef1() = fun () = this
|
||||
fun Int.thisRef2() = fun (): Int {return this}
|
||||
|
||||
fun <T> T.genericThisRef1() = fun () = this
|
||||
fun <T> T.genericThisRef2() = fun (): T {return this}
|
||||
|
||||
val Int.valThisRef1: () -> Int get() = fun () = this
|
||||
val Int.valThisRef2: () -> Int get() = fun (): Int {return this}
|
||||
|
||||
val <T> T.valGenericThisRef1: ()->T get() = fun () = this
|
||||
val <T> T.valGenericThisRef2: ()->T get() = fun (): T {return this}
|
||||
|
||||
val <T> T.withLabel1: ()->T get() = fun () = this@withLabel1
|
||||
val <T> T.withLabel2: ()->T get() = fun (): T {return this@withLabel2}
|
||||
|
||||
fun box(): String {
|
||||
if (1.thisRef1()() != 1) return "Test 1 failed"
|
||||
if (2.thisRef2()() != 2) return "Test 2 failed"
|
||||
|
||||
if (3.genericThisRef1()() != 3) return "Test 3 failed"
|
||||
if (4.genericThisRef2()() != 4) return "Test 4 failed"
|
||||
|
||||
if (5.valThisRef1() != 5) return "Test 5 failed"
|
||||
if (6.valThisRef2() != 6) return "Test 6 failed"
|
||||
|
||||
if (7.valGenericThisRef1() != 7) return "Test 7 failed"
|
||||
if (8.valGenericThisRef2() != 8) return "Test 8 failed"
|
||||
|
||||
if ("bar".withLabel1() != "bar") return "Test 9 failed"
|
||||
if ("bar".withLabel2() != "bar") return "Test 10 failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
fun Any.foo1() : ()-> String {
|
||||
return { "239" + this }
|
||||
}
|
||||
|
||||
fun Int.foo2() : (i : Int) -> Int {
|
||||
return { x -> x + this }
|
||||
}
|
||||
|
||||
fun <T> fooT1(t : T) = { t.toString() }
|
||||
|
||||
fun <T> fooT2(t: T) = { x:T -> t.toString() + x.toString() }
|
||||
|
||||
object t
|
||||
|
||||
fun box() : String {
|
||||
if( (10.foo1())() != "23910") return "foo1 fail"
|
||||
if( (10.foo2())(1) != 11 ) return "foo2 fail"
|
||||
|
||||
if(1.(fun Int.() = this + 1)() != 2) return "test 3 failed";
|
||||
if( {1}() != 1) return "test 4 failed";
|
||||
if( {x : Int -> x}(1) != 1) return "test 5 failed";
|
||||
if( 1.(fun Int.(x: Int) = x + this)(1) != 2) return "test 6 failed";
|
||||
if( t.(fun Any.() = this)() != t) return "test 7 failed";
|
||||
if( (fooT1<String>("mama"))() != "mama") return "test 8 failed";
|
||||
if( (fooT2<String>("mama"))("papa") != "mamapapa") return "test 9 failed";
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
fun foo(block: (String, String, String) -> String): String = block("O", "fail", "K")
|
||||
|
||||
fun box() = foo(fun(x: String, _: String, y: String) = x + y)
|
||||
@@ -0,0 +1,38 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
fun check(expected: String, obj: Any?) {
|
||||
val actual = obj.toString()
|
||||
if (actual != expected)
|
||||
throw AssertionError("Expected: $expected, actual: $actual")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check("() -> kotlin.Unit")
|
||||
{ -> }
|
||||
check("() -> kotlin.Int")
|
||||
{ -> 42 }
|
||||
check("(kotlin.String) -> kotlin.Long",
|
||||
fun (s: String) = 42.toLong())
|
||||
check("(kotlin.Int, kotlin.Int) -> kotlin.Unit")
|
||||
{ x: Int, y: Int -> }
|
||||
|
||||
check("kotlin.Int.() -> kotlin.Unit",
|
||||
fun Int.() {})
|
||||
check("kotlin.Unit.() -> kotlin.Int?",
|
||||
fun Unit.(): Int? = 42)
|
||||
check("kotlin.String.(kotlin.String?) -> kotlin.Long",
|
||||
fun String.(s: String?): Long = 42.toLong())
|
||||
check("kotlin.collections.List<kotlin.String>.(kotlin.collections.MutableSet<*>, kotlin.Nothing) -> kotlin.Unit",
|
||||
fun List<String>.(x: MutableSet<*>, y: Nothing) {})
|
||||
|
||||
check("(kotlin.IntArray, kotlin.ByteArray, kotlin.ShortArray, kotlin.CharArray, kotlin.LongArray, kotlin.BooleanArray, kotlin.FloatArray, kotlin.DoubleArray) -> kotlin.Array<kotlin.Int>",
|
||||
fun (ia: IntArray, ba: ByteArray, sa: ShortArray, ca: CharArray, la: LongArray, za: BooleanArray, fa: FloatArray, da: DoubleArray): Array<Int> = null!!)
|
||||
|
||||
check("(kotlin.Array<kotlin.Array<kotlin.Array<kotlin.collections.List<kotlin.String>>>>) -> kotlin.Comparable<kotlin.String>",
|
||||
fun (a: Array<Array<Array<List<String>>>>): Comparable<String> = null!!)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun <T> bar(): String {
|
||||
return { t: T -> t }.toString()
|
||||
}
|
||||
|
||||
class Baz<T, V> {
|
||||
fun <V : T> baz(v: V): String {
|
||||
return (fun(t: List<T>): V = v).toString()
|
||||
}
|
||||
}
|
||||
|
||||
open class Foo<T, U : List<T>>(val lambda: (T) -> U)
|
||||
class Bar<T> : Foo<T, List<T>>({ listOf(it) })
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("(T) -> T", bar<String>())
|
||||
assertEquals("(kotlin.collections.List<T>) -> V", Baz<String, Int>().baz<String>(""))
|
||||
assertEquals("(T) -> kotlin.collections.List<T>", Bar<Int>().lambda.toString())
|
||||
return "OK"
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
fun check(expected: String, obj: Any?) {
|
||||
val actual = obj.toString()
|
||||
if (actual != expected)
|
||||
throw AssertionError("Expected: $expected, actual: $actual")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check("Function0<kotlin.Unit>")
|
||||
{ -> }
|
||||
check("Function0<java.lang.Integer>")
|
||||
{ -> 42 }
|
||||
check("Function1<java.lang.String, java.lang.Long>",
|
||||
fun (s: String) = 42.toLong())
|
||||
check("Function2<java.lang.Integer, java.lang.Integer, kotlin.Unit>")
|
||||
{ x: Int, y: Int -> }
|
||||
|
||||
check("Function1<java.lang.Integer, kotlin.Unit>",
|
||||
fun Int.() {})
|
||||
check("Function1<kotlin.Unit, java.lang.Integer>",
|
||||
fun Unit.(): Int? = 42)
|
||||
check("Function2<java.lang.String, java.lang.String, java.lang.Long>",
|
||||
fun String.(s: String?): Long = 42.toLong())
|
||||
check("Function3<java.util.List<? extends java.lang.String>, java.util.Set<?>, ?, kotlin.Unit>",
|
||||
fun List<String>.(x: MutableSet<*>, y: Nothing) {})
|
||||
|
||||
check("Function8<int[], byte[], short[], char[], long[], boolean[], float[], double[], java.lang.Integer[]>",
|
||||
fun (ia: IntArray, ba: ByteArray, sa: ShortArray, ca: CharArray, la: LongArray, za: BooleanArray, fa: FloatArray, da: DoubleArray): Array<Int> = null!!)
|
||||
|
||||
check("Function1<java.util.List<? extends java.lang.String>[][][], java.lang.Comparable<? super java.lang.String>>",
|
||||
fun (a: Array<Array<Array<List<String>>>>): Comparable<String> = null!!)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
infix fun Int.test(x : Int) : Int {
|
||||
if (this > 1) {
|
||||
return (this - 1) test x
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
fun box() : String = if (10.test(10) == 1) "OK" else "FAIL"
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fun box(): String {
|
||||
val f = fun (s: String): String = s
|
||||
val g = f as String.() -> String
|
||||
if ("OK".g() != "OK") return "Fail 1"
|
||||
|
||||
val h = fun String.(): String = this
|
||||
val i = h as (String) -> String
|
||||
if (i("OK") != "OK") return "Fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
class A
|
||||
|
||||
class B {
|
||||
operator fun A.invoke() = "##"
|
||||
operator fun A.invoke(i: Int) = "#${i}"
|
||||
}
|
||||
|
||||
fun foo() = A()
|
||||
|
||||
fun B.test(): String {
|
||||
if (A()() != "##") return "fail1"
|
||||
if (A()(1) != "#1") return "fail2"
|
||||
if (foo()() != "##") return "fail3"
|
||||
if (foo()(42) != "#42") return "fail4"
|
||||
if ((foo())(42) != "#42") return "fail5"
|
||||
if ({ -> A()}()() != "##") return "fail6"
|
||||
if ({ -> A()}()(37) != "#37") return "fail7"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun box(): String = B().test()
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
class TestClass {
|
||||
companion object {
|
||||
inline operator fun <T> invoke(task: () -> T) = task()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test1 = TestClass { "K" }
|
||||
if (test1 != "K") return "fail1, 'test1' == $test1"
|
||||
|
||||
val ok = "OK"
|
||||
|
||||
val x = TestClass { return ok }
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class TestClass {
|
||||
inline operator fun <T> invoke(task: () -> T) = task()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = TestClass()
|
||||
val ok = "OK"
|
||||
|
||||
val x = test { return ok }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package invoke
|
||||
|
||||
fun test1(predicate: (Int) -> Int, i: Int) = predicate(i)
|
||||
|
||||
fun test2(predicate: (Int) -> Int, i: Int) = predicate.invoke(i)
|
||||
|
||||
class Method {
|
||||
operator fun invoke(i: Int) = i
|
||||
}
|
||||
|
||||
fun test3(method: Method, i: Int) = method.invoke(i)
|
||||
|
||||
fun test4(method: Method, i: Int) = method(i)
|
||||
|
||||
class Method2 {}
|
||||
|
||||
operator fun Method2.invoke(s: String) = s
|
||||
|
||||
fun test5(method2: Method2, s: String) = method2(s)
|
||||
|
||||
fun box() : String {
|
||||
if (test1({ it }, 1) != 1) return "fail 1"
|
||||
if (test2({ it }, 2) != 2) return "fail 2"
|
||||
if (test3(Method(), 3) != 3) return "fail 3"
|
||||
if (test4(Method(), 4) != 4) return "fail 4"
|
||||
if (test5(Method2(), "s") != "s") return "fail5"
|
||||
return "OK"
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
//KT-3217 Invoke convention after function invocation doesn't work
|
||||
//KT-2728 Can't compile A()()
|
||||
|
||||
class A {
|
||||
operator fun invoke() = "##"
|
||||
operator fun invoke(i: Int) = "#${i}"
|
||||
}
|
||||
|
||||
fun foo() = A()
|
||||
|
||||
fun box(): String {
|
||||
if (A()() != "##") return "fail1"
|
||||
if (A()(1) != "#1") return "fail2"
|
||||
if (foo()() != "##") return "fail3"
|
||||
if (foo()(42) != "#42") return "fail4"
|
||||
if ((foo())(42) != "#42") return "fail5"
|
||||
if ({ -> A()}()() != "##") return "fail6"
|
||||
if ({ -> A()}()(37) != "#37") return "fail7"
|
||||
return "OK"
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public class JavaClass {
|
||||
public String getO() {
|
||||
return "O";
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
// KT-9522 Allow invoke convention for synthetic property
|
||||
|
||||
operator fun String.invoke() = this + "K"
|
||||
|
||||
fun box(): String {
|
||||
return JavaClass().o();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//KT-3189 Function invoke is called with no reason
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val bad = Bad({ 1 })
|
||||
|
||||
return if (bad.test() == 1) "OK" else "fail"
|
||||
}
|
||||
|
||||
class Bad(val a: () -> Int) {
|
||||
|
||||
fun test(): Int = a()
|
||||
|
||||
operator fun invoke(): Int = 2
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//KT-3190 Compiler crash if function called 'invoke' calls a closure
|
||||
// IGNORE_BACKEND: JS
|
||||
// JS backend does not allow to implement Function{N} interfaces
|
||||
|
||||
fun box(): String {
|
||||
val test = Cached<Int,Int>({ it + 2 })
|
||||
return if (test(1) == 3) "OK" else "fail"
|
||||
}
|
||||
|
||||
class Cached<K, V>(private val generate: (K)->V): Function1<K, V> {
|
||||
val store = HashMap<K, V>()
|
||||
|
||||
// Everything works just fine if 'invoke' method is renamed to, for example, 'get'
|
||||
override fun invoke(p1: K) = store.getOrPut(p1) { generate(p1) }
|
||||
}
|
||||
|
||||
//from library
|
||||
fun <K,V> MutableMap<K,V>.getOrPut(key: K, defaultValue: ()-> V) : V {
|
||||
if (this.containsKey(key)) {
|
||||
return this.get(key) as V
|
||||
} else {
|
||||
val answer = defaultValue()
|
||||
this.put(key, answer)
|
||||
return answer
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
//KT-3297 Calling the wrong function inside an extension method to the Function0 class
|
||||
|
||||
infix fun <R> Function0<R>.or(alt: () -> R): R {
|
||||
try {
|
||||
return this()
|
||||
} catch (e: Exception) {
|
||||
return alt()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return {
|
||||
throw RuntimeException("fail")
|
||||
} or {
|
||||
"OK"
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
//KT-3450 get and invoke are not parsed in one expression
|
||||
|
||||
public class A(val s: String) {
|
||||
|
||||
operator fun get(i: Int) : A = A("$s + $i")
|
||||
|
||||
operator fun invoke(builder : A.() -> String): String = builder()
|
||||
}
|
||||
fun x(y : String) : A = A(y)
|
||||
|
||||
fun foo() = x("aaa")[42] { "$s!!" }
|
||||
|
||||
fun box() = if (foo() == "aaa + 42!!") "OK" else "fail"
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
//KT-3631 String.invoke doesn't work with literals
|
||||
|
||||
operator fun String.invoke(i: Int) = "$this$i"
|
||||
|
||||
fun box() = if ("a"(12) == "a12") "OK" else "fail"
|
||||
@@ -0,0 +1,21 @@
|
||||
//KT-3772 Invoke and overload resolution ambiguity
|
||||
|
||||
open class A {
|
||||
fun invoke(f: A.() -> Unit) = 1
|
||||
}
|
||||
|
||||
class B {
|
||||
operator fun invoke(f: B.() -> Unit) = 2
|
||||
}
|
||||
|
||||
open class C
|
||||
val C.attr: A get() = A()
|
||||
|
||||
open class D: C()
|
||||
val D.attr: B get() = B()
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val d = D()
|
||||
return if (d.attr {} == 2) "OK" else "fail"
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
//KT-3821 Invoke convention doesn't work for `this`
|
||||
|
||||
class A() {
|
||||
operator fun invoke() = 42
|
||||
fun foo() = this() // Expecting a function type, but found A
|
||||
}
|
||||
|
||||
fun box() = if (A().foo() == 42) "OK" else "fail"
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
//KT-3822 Compiler crashes when use invoke convention with `this` in class which extends Function0<T>
|
||||
// IGNORE_BACKEND: JS
|
||||
// JS backend does not allow to implement Function{N} interfaces
|
||||
|
||||
class B() : Function0<Boolean> {
|
||||
override fun invoke() = true
|
||||
|
||||
fun foo() = this() // Exception
|
||||
}
|
||||
|
||||
fun box() = if (B().foo()) "OK" else "fail"
|
||||
@@ -0,0 +1,64 @@
|
||||
//KT-1038 Cannot compile lazy iterators
|
||||
|
||||
class YieldingIterator<T>(val yieldingFunction : ()->T?) : Iterator<T>
|
||||
{
|
||||
var current : T? = yieldingFunction()
|
||||
override fun next(): T {
|
||||
val next = current;
|
||||
if (next != null)
|
||||
{
|
||||
current = yieldingFunction()
|
||||
return next
|
||||
}
|
||||
else throw IndexOutOfBoundsException()
|
||||
}
|
||||
override fun hasNext(): Boolean = current != null
|
||||
}
|
||||
|
||||
class YieldingIterable<T>(val yielderFactory : ()->(()->T?)) : Iterable<T>
|
||||
{
|
||||
override fun iterator(): Iterator<T> = YieldingIterator(yielderFactory())
|
||||
}
|
||||
|
||||
public fun<TItem> Iterable<TItem>.lazy() : Iterable<TItem>
|
||||
{
|
||||
return YieldingIterable {
|
||||
val iterator = this.iterator();
|
||||
{ if (iterator.hasNext()) iterator.next() else null }
|
||||
}
|
||||
}
|
||||
|
||||
infix fun<TItem> Iterable<TItem>.where(predicate : (TItem)->Boolean) : Iterable<TItem>
|
||||
{
|
||||
return YieldingIterable {
|
||||
val iterator = this.iterator()
|
||||
fun yielder() : TItem? {
|
||||
while(iterator.hasNext())
|
||||
{
|
||||
val next = iterator.next()
|
||||
if (predicate(next))
|
||||
return next
|
||||
}
|
||||
return null
|
||||
}
|
||||
{ yielder() }
|
||||
}
|
||||
}
|
||||
|
||||
infix fun<TItem, TResult> Iterable<TItem>.select(selector : (TItem)->TResult) : Iterable<TResult>
|
||||
{
|
||||
return YieldingIterable {
|
||||
val iterator = this.iterator();
|
||||
{ if(iterator.hasNext()) selector(iterator.next()) else null }
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val x = 0..100
|
||||
val filtered = x where { it % 2 == 0 }
|
||||
val xx = x select { it * 2 }
|
||||
var res = 0
|
||||
for (x in xx)
|
||||
res += x
|
||||
return if (res == 10100) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
|
||||
interface MyIterator<T> {
|
||||
operator fun hasNext() : Boolean
|
||||
operator fun next() : T
|
||||
}
|
||||
|
||||
operator fun <T : Any> T?.iterator() = object : MyIterator<T> {
|
||||
var hasNext = this@iterator != null
|
||||
private set
|
||||
override fun hasNext() = hasNext
|
||||
|
||||
override fun next() : T {
|
||||
if (hasNext) {
|
||||
hasNext = false
|
||||
return this@iterator!!
|
||||
}
|
||||
throw java.util.NoSuchElementException()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
var k = 0
|
||||
for (i in 1) {
|
||||
k++
|
||||
}
|
||||
return if(k == 1) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package t
|
||||
|
||||
interface I{
|
||||
fun f()
|
||||
}
|
||||
|
||||
class Test{
|
||||
fun foo(){
|
||||
val i : I = object : I {
|
||||
override fun f() {
|
||||
fun local(){
|
||||
bar()
|
||||
}
|
||||
local()
|
||||
}
|
||||
}
|
||||
i.f()
|
||||
}
|
||||
|
||||
fun bar(){}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
Test().foo()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
interface A {
|
||||
val method : (() -> Unit)?
|
||||
}
|
||||
|
||||
fun test(a : A) {
|
||||
if (a.method != null) {
|
||||
a.method!!()
|
||||
}
|
||||
}
|
||||
|
||||
class B : A {
|
||||
override val method = { }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(B())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
interface A {
|
||||
val method : () -> Unit?
|
||||
}
|
||||
|
||||
fun test(a : A) {
|
||||
if (a.method != null) {
|
||||
a.method!!()
|
||||
}
|
||||
}
|
||||
|
||||
class B : A {
|
||||
override val method = { }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(B())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
public class RunnableFunctionWrapper(val f : () -> Unit) : Runnable {
|
||||
public override fun run() {
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
var res = ""
|
||||
RunnableFunctionWrapper({ res = "OK" }).run()
|
||||
return res
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class A(
|
||||
val i : Int,
|
||||
val j : Int = i
|
||||
)
|
||||
|
||||
fun box() = if (A(1).j == 1) "OK" else "fail"
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo(i: Int, j: Int = i) = j
|
||||
|
||||
fun box() = if (foo(1) == 1) "OK" else "fail"
|
||||
@@ -0,0 +1,7 @@
|
||||
fun box(): String {
|
||||
fun rmrf(i: Int) {
|
||||
if (i > 0) rmrf(i - 1)
|
||||
}
|
||||
rmrf(5)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fun box() =
|
||||
B().method()
|
||||
|
||||
public open class A(){
|
||||
public open fun method() : String = "OK"
|
||||
}
|
||||
|
||||
public class B(): A(){
|
||||
public override fun method() : String {
|
||||
return ({
|
||||
super.method()
|
||||
})()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package someTest
|
||||
|
||||
public class Some private constructor(val v: String) {
|
||||
companion object {
|
||||
public fun init(v: String): Some {
|
||||
return Some(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = Some.init("OK").v
|
||||
@@ -0,0 +1,10 @@
|
||||
// KT-2739 Error type inferred for hashSet(Pair, Pair, Pair)
|
||||
|
||||
fun <T> foo(vararg ts: T): T? = null
|
||||
|
||||
class Pair<A>(a: A)
|
||||
|
||||
fun box(): String {
|
||||
val v = foo(Pair(1))
|
||||
return if (v == null) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(): Int {
|
||||
val a = "test"
|
||||
val b = "test"
|
||||
return a.compareTo(b)
|
||||
}
|
||||
|
||||
fun box(): String = if(foo() == 0) "OK" else "Fail"
|
||||
@@ -0,0 +1,33 @@
|
||||
class A {
|
||||
fun get(vararg x: Int) = x.size
|
||||
}
|
||||
|
||||
class B {
|
||||
fun get(vararg x: Unit) = x.size
|
||||
}
|
||||
|
||||
fun test1(a: A): Int {
|
||||
return a.get(1)
|
||||
}
|
||||
|
||||
fun test2(a: A): Int {
|
||||
return a.get(1, 2)
|
||||
}
|
||||
|
||||
fun test3(b: B): Int {
|
||||
return b.get(Unit, Unit)
|
||||
}
|
||||
|
||||
|
||||
fun box() : String {
|
||||
var result = test1(A())
|
||||
if (result != 1) return "fail1: $result"
|
||||
|
||||
result = test2(A())
|
||||
if (result != 2) return "fail2: $result"
|
||||
|
||||
result = test3(B())
|
||||
if (result != 2) return "fail3: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun <T> foo(t: T) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
foo(null)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class Data
|
||||
|
||||
fun newInit(f: Data.() -> Data) = Data().f()
|
||||
|
||||
class TestClass {
|
||||
val test: Data = newInit() { this }
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
TestClass()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
class Comment() {
|
||||
var article = ""
|
||||
}
|
||||
|
||||
fun new(body: Comment.() -> Unit) : Comment {
|
||||
val c = Comment()
|
||||
c.body()
|
||||
return c
|
||||
}
|
||||
|
||||
open class Request(val handler : Any.() -> Comment) {
|
||||
val s = handler().article
|
||||
}
|
||||
|
||||
|
||||
class A : Request ({
|
||||
new {
|
||||
this.article = "OK"
|
||||
}
|
||||
})
|
||||
|
||||
fun box() : String {
|
||||
return A().s
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fun Any.with(operation : Any.() -> Any) = operation().toString()
|
||||
|
||||
val f = { a : Int -> }
|
||||
|
||||
fun box () : String {
|
||||
return if(20.with {
|
||||
this
|
||||
} == "20")
|
||||
"OK"
|
||||
else
|
||||
"fail"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class A() {
|
||||
var x : Int = 0
|
||||
|
||||
var z = {
|
||||
x++
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val a = A()
|
||||
a.z() //problem is here
|
||||
return if (a.x == 1) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fun box() : String {
|
||||
val fps : Double = 1.toDouble()
|
||||
var mspf : Long
|
||||
{
|
||||
if ((fps.toInt() == 0))
|
||||
mspf = 0
|
||||
else
|
||||
mspf = (((1000.0 / fps)).toLong())
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
fun IntRange.forEach(body : (Int) -> Unit) {
|
||||
for(i in this) {
|
||||
body(i)
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
var seed = 0
|
||||
|
||||
fun local(x: Int) {
|
||||
fun deep() {
|
||||
seed += x
|
||||
}
|
||||
fun deep2(x : Int) {
|
||||
seed += x
|
||||
}
|
||||
fun Int.iter() {
|
||||
seed += this
|
||||
}
|
||||
|
||||
deep()
|
||||
deep2(-x)
|
||||
x.iter()
|
||||
seed += x
|
||||
}
|
||||
|
||||
for(i in 1..5) {
|
||||
fun Int.iter() {
|
||||
seed += this
|
||||
}
|
||||
|
||||
local(i)
|
||||
(-i).iter()
|
||||
}
|
||||
|
||||
fun local2(y: Int) {
|
||||
seed += y
|
||||
}
|
||||
|
||||
(1..5).forEach {
|
||||
local2(it)
|
||||
}
|
||||
|
||||
|
||||
return if(seed == 30) "OK" else seed.toString()
|
||||
}
|
||||
Vendored
+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"
|
||||
}
|
||||
backend.native/tests/external/codegen/box/functions/localFunctions/definedWithinLambdaInnerUsage1.kt
Vendored
+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"
|
||||
}
|
||||
backend.native/tests/external/codegen/box/functions/localFunctions/definedWithinLambdaInnerUsage2.kt
Vendored
+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"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fun outer() {
|
||||
fun inner(i: Int) {
|
||||
if (i > 0){
|
||||
{
|
||||
it: Int -> inner(0) // <- invocation of literal itself is generated instead
|
||||
}.invoke(1)
|
||||
}
|
||||
}
|
||||
inner(1)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
outer()
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun box(): String {
|
||||
fun <T> foo(t: T) = t
|
||||
|
||||
return foo("OK")
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun box() : String {
|
||||
|
||||
|
||||
fun local(i: Int = 1) : Int {
|
||||
return i
|
||||
}
|
||||
|
||||
return if (local() != 1) "fail" else "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fun foo(f: (Int?) -> Int): Int {
|
||||
return f(0)
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
infix operator fun Int?.plus(a: Int) : Int = a!! + 2
|
||||
|
||||
if (foo { it + 1 } != 3) return "Fail 1"
|
||||
if (foo { it plus 1 } != 3) return "Fail 2"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
fun box(): String {
|
||||
infix fun Int.foo(a: Int): Int = a + 2
|
||||
|
||||
val s = object {
|
||||
fun test(): Int {
|
||||
return 1 foo 1
|
||||
}
|
||||
}
|
||||
|
||||
fun local(): Int {
|
||||
return 1 foo 1
|
||||
}
|
||||
|
||||
if (s.test() != 3) return "Fail"
|
||||
|
||||
if (local() != 3) return "Fail"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun box(): String {
|
||||
fun String.f() = this
|
||||
val vf: String.() -> String = { this }
|
||||
|
||||
val localExt = "O".f() + "K"?.f()
|
||||
if (localExt != "OK") return "localExt $localExt"
|
||||
|
||||
return "O".vf() + "K"?.vf()
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
var result = "Fail"
|
||||
|
||||
val p = object : Runnable {
|
||||
override fun run() {
|
||||
fun <T : Any> T.id() = this
|
||||
|
||||
result = "OK".id()
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
p.run()
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
class T(val value: Int) {
|
||||
}
|
||||
|
||||
fun local() : Int {
|
||||
|
||||
operator fun T.get(s: Int): Int {
|
||||
return s * this.value
|
||||
}
|
||||
|
||||
var t = T(11)
|
||||
return t[2]
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if (local() != 22) return "fail1 ${local()} "
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
open class T(var value: Int) {}
|
||||
|
||||
fun plusAssign(): T {
|
||||
|
||||
operator fun T.plusAssign(s: Int) {
|
||||
value += s
|
||||
}
|
||||
|
||||
var t = T(1)
|
||||
t += 1
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = plusAssign().value
|
||||
if (result != 2) return "fail 1: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
class It(val id: String)
|
||||
|
||||
fun box(): String {
|
||||
val projectId = "projectId"
|
||||
val it = It("it")
|
||||
|
||||
|
||||
fun selectMetaRunnerId(): String {
|
||||
operator fun Int?.inc() = (this ?: 0) + 1
|
||||
var counter: Int? = null
|
||||
fun path(metaRunnerId: String) = counter != 2
|
||||
|
||||
var i = 0
|
||||
while (true) {
|
||||
val name = projectId + "_" + it.id + (if (counter == null) "" else "_$counter")
|
||||
if (!path(name)) {
|
||||
return name
|
||||
}
|
||||
counter++
|
||||
|
||||
i++
|
||||
if (i > 2) return "Infinity loop: $counter"
|
||||
}
|
||||
}
|
||||
val X = selectMetaRunnerId()
|
||||
if (X != projectId + "_" + it.id + "_2") return "fail: $X"
|
||||
return "OK"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
open class T(var value: Int) {}
|
||||
|
||||
fun localExtensionOnNullableParameter(): T {
|
||||
|
||||
fun T.local(s: Int) {
|
||||
value += s
|
||||
}
|
||||
|
||||
var t: T? = T(1)
|
||||
t?.local(2)
|
||||
|
||||
return t!!
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val result = localExtensionOnNullableParameter().value
|
||||
if (result != 3) return "fail 2: $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
class Test {
|
||||
|
||||
val property:Int
|
||||
init {
|
||||
fun local():Int {
|
||||
return 10;
|
||||
}
|
||||
property = local();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return if (Test().property == 10) "OK" else "fail"
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fun simple() = fun (): Boolean { return true }
|
||||
|
||||
fun withLabel() = l@ fun (): Boolean { return@l true }
|
||||
|
||||
fun box(): String {
|
||||
if (!simple()()) return "Test simple failed"
|
||||
if (!withLabel()()) return "Test withLabel failed"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fun foo(x: Int) {}
|
||||
|
||||
fun loop(times : Int) {
|
||||
var left = times
|
||||
while(left > 0) {
|
||||
val u : (value : Int) -> Unit = {
|
||||
foo(it)
|
||||
}
|
||||
u(left--)
|
||||
}
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
loop(5)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
operator fun String.unaryPlus() : String {
|
||||
if (this == "") {
|
||||
return "done"
|
||||
}
|
||||
return +""
|
||||
}
|
||||
|
||||
fun box() : String = if (+"11" == "done") "OK" else "FAIL"
|
||||
@@ -0,0 +1,11 @@
|
||||
class C
|
||||
|
||||
operator fun C.compareTo(o: C) : Int {
|
||||
if (this == o) return 0
|
||||
if (o >= o) {
|
||||
return 1
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
fun box() : String = if (C() > C()) "OK" else "FAIL"
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
operator fun String.inc() : String {
|
||||
if (this == "") {
|
||||
return "done"
|
||||
}
|
||||
var s = ""
|
||||
return ++s
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
var s = "11test"
|
||||
return if (++s == "done") "OK" else "FAIL"
|
||||
}
|
||||
Reference in New Issue
Block a user