Migrate testdata to new lambda syntax
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
fun box(): String {
|
||||
fun rec(n : Int) {
|
||||
val x = { (m : Int) ->
|
||||
val x = { m : Int ->
|
||||
if (n > 0) rec(n - 1)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fun box() : String {
|
||||
return apply( "OK", {(arg: String) -> arg } )
|
||||
return apply( "OK", {arg: String -> arg } )
|
||||
}
|
||||
|
||||
fun apply(arg : String, f : (p:String) -> String) : String {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fun box() : String {
|
||||
return if (apply( 5, {(arg: Int) -> arg + 13 } ) == 18) "OK" else "fail"
|
||||
return if (apply( 5, {arg: Int -> arg + 13 } ) == 18) "OK" else "fail"
|
||||
}
|
||||
|
||||
fun apply(arg : Int, f : (p:Int) -> Int) : Int {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Point(val x:Int, val y:Int) {
|
||||
fun mul() : (scalar:Int)->Point {
|
||||
return { (scalar:Int):Point -> Point(x * scalar, y * scalar) }
|
||||
return { scalar:Int -> Point(x * scalar, y * scalar) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Point(val x : Int, val y : Int)
|
||||
|
||||
fun box() : String {
|
||||
val answer = apply(Point(3, 5), { Point.(scalar : Int) : Point ->
|
||||
val answer = apply(Point(3, 5), { scalar : Int ->
|
||||
Point(x * scalar, y * scalar)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
fun box(): String {
|
||||
val a = 1
|
||||
val explicitlyReturned = run1 @f{(): String ->
|
||||
val explicitlyReturned = run1 @f{
|
||||
if (a > 0)
|
||||
return@f "OK"
|
||||
else "Fail 1"
|
||||
}
|
||||
if (explicitlyReturned != "OK") return explicitlyReturned
|
||||
|
||||
val implicitlyReturned = run1 @f{(): String ->
|
||||
val implicitlyReturned = run1 @f{
|
||||
if (a < 0)
|
||||
return@f "Fail 2"
|
||||
else "OK"
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
fun box(): String {
|
||||
val a = 1
|
||||
val explicitlyReturned = run1 {(): String ->
|
||||
val explicitlyReturned = run1 {
|
||||
if (a > 0)
|
||||
return@run1 "OK"
|
||||
else "Fail 1"
|
||||
}
|
||||
if (explicitlyReturned != "OK") return explicitlyReturned
|
||||
|
||||
val implicitlyReturned = run1 {(): String ->
|
||||
val implicitlyReturned = run1 {
|
||||
if (a < 0)
|
||||
return@run1 "Fail 2"
|
||||
else "OK"
|
||||
|
||||
@@ -5,7 +5,7 @@ fun main(args: Array<String>?) {
|
||||
//do not compile
|
||||
System.out?.println(fff<Unit>(Unit)) //do not compile
|
||||
System.out?.println(id<Unit>(y)) //do not compile
|
||||
System.out?.println(fff<Unit>(id<Unit>(y)) == id<Unit>(foreach(arrayOfNulls<Int>(0) as Array<Int>,{(e : Int) : Unit -> }))) //do not compile
|
||||
System.out?.println(fff<Unit>(id<Unit>(y)) == id<Unit>(foreach(arrayOfNulls<Int>(0) as Array<Int>,{ e : Int -> }))) //do not compile
|
||||
}
|
||||
class A<T>()
|
||||
|
||||
@@ -34,8 +34,8 @@ fun box() : String {
|
||||
a[0] = 0
|
||||
a[1] = 1
|
||||
a[2] = 2
|
||||
foreach(a, { (el : Int) : Unit -> System.out?.println(el) })
|
||||
almostFilter(a, { (el : Int) : Int -> el })
|
||||
foreach(a, { el : Int -> System.out?.println(el) })
|
||||
almostFilter(a, { el : Int -> el })
|
||||
main(null)
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//KT-1061 Can't call function defined as a val
|
||||
|
||||
object X {
|
||||
val doit = { (i: Int) -> i }
|
||||
val doit = { i: Int -> i }
|
||||
}
|
||||
|
||||
fun box() : String = if (X.doit(3) == 3) "OK" else "fail"
|
||||
|
||||
@@ -6,7 +6,7 @@ class Foo<T>(val filter: (T) -> Boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
fun foo() = Foo({ (i: Int) -> i < 5 }).bar(2)
|
||||
fun foo() = Foo({ i: Int -> i < 5 }).bar(2)
|
||||
|
||||
fun box() : String {
|
||||
if (!foo()) return "fail"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
fun box() : String {
|
||||
val y = 12
|
||||
val op = { (x:Int) -> (x + y).toString() }
|
||||
val op = { x:Int -> (x + y).toString() }
|
||||
|
||||
val op2 : Int.(Int) -> String = { op(this + it) }
|
||||
|
||||
|
||||
@@ -8,17 +8,17 @@ fun Int.foo2() : (i : Int) -> Int {
|
||||
|
||||
fun fooT1<T>(t : T) = { t.toString() }
|
||||
|
||||
fun fooT2<T>(t: T) = { (x:T) -> t.toString() + x.toString() }
|
||||
fun fooT2<T>(t: T) = { x:T -> t.toString() + x.toString() }
|
||||
|
||||
fun box() : String {
|
||||
if( (10.foo1())() != "23910") return "foo1 fail"
|
||||
if( (10.foo2())(1) != 11 ) return "foo2 fail"
|
||||
|
||||
if(1.{Int.() -> this + 1}() != 2) return "test 3 failed";
|
||||
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.{Int.(x : Int) -> x + this}(1) != 2) return "test 6 failed";
|
||||
if( 1.({Int.() -> this})() != 1) return "test 7 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( 1.(fun Int.() = this)() != 1) 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"
|
||||
|
||||
@@ -7,22 +7,22 @@ fun check(expected: String, obj: Any?) {
|
||||
|
||||
fun box(): String {
|
||||
check("kotlin.Function0<kotlin.Unit>")
|
||||
{ () : Unit -> }
|
||||
{ -> }
|
||||
check("kotlin.Function0<java.lang.Integer>")
|
||||
{ () : Int -> 42 }
|
||||
check("kotlin.Function1<java.lang.String, java.lang.Long>")
|
||||
{ (s: String) : Long -> 42.toLong() }
|
||||
{ -> 42 }
|
||||
check("kotlin.Function1<java.lang.String, java.lang.Long>",
|
||||
fun (s: String) = 42.toLong())
|
||||
check("kotlin.Function2<java.lang.Integer, java.lang.Integer, kotlin.Unit>")
|
||||
{ (x: Int, y: Int) : Unit -> }
|
||||
{ x: Int, y: Int -> }
|
||||
|
||||
check("kotlin.ExtensionFunction0<java.lang.Integer, kotlin.Unit>")
|
||||
{ Int.() : Unit -> }
|
||||
check("kotlin.ExtensionFunction0<kotlin.Unit, java.lang.Integer>")
|
||||
{ Unit.() : Int -> 42 }
|
||||
check("kotlin.ExtensionFunction1<java.lang.String, java.lang.String, java.lang.Long>")
|
||||
{ String.(s: String) : Long -> 42.toLong() }
|
||||
check("kotlin.ExtensionFunction2<java.lang.Integer, java.lang.Integer, java.lang.Integer, kotlin.Unit>")
|
||||
{ Int.(x: Int, y: Int) : Unit -> }
|
||||
check("kotlin.ExtensionFunction0<java.lang.Integer, kotlin.Unit>",
|
||||
fun Int.() {})
|
||||
check("kotlin.ExtensionFunction0<kotlin.Unit, java.lang.Integer>",
|
||||
fun Unit.(): Int = 42)
|
||||
check("kotlin.ExtensionFunction1<java.lang.String, java.lang.String, java.lang.Long>",
|
||||
fun String.(s: String): Long = 42.toLong())
|
||||
check("kotlin.ExtensionFunction2<java.lang.Integer, java.lang.Integer, java.lang.Integer, kotlin.Unit>",
|
||||
fun Int.(x: Int, y: Int) {})
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,8 @@ fun B.test(): String {
|
||||
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"
|
||||
if ({ -> A()}()() != "##") return "fail6"
|
||||
if ({ -> A()}()(37) != "#37") return "fail7"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ fun box(): String {
|
||||
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"
|
||||
if ({ -> A()}()() != "##") return "fail6"
|
||||
if ({ -> A()}()(37) != "#37") return "fail7"
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
fun Any.with(operation : Any.() -> Any) = operation().toString()
|
||||
|
||||
val f = { (a : Int) :Unit -> }
|
||||
val f = { a : Int -> }
|
||||
|
||||
fun box () : String {
|
||||
return if(20.with {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class A() {
|
||||
var x : Int = 0
|
||||
|
||||
var z = { () ->
|
||||
var z = {
|
||||
x++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ fun outer() {
|
||||
fun inner(i: Int) {
|
||||
if (i > 0){
|
||||
{
|
||||
(it: Int) -> inner(0) // <- invocation of literal itself is generated instead
|
||||
it: Int -> inner(0) // <- invocation of literal itself is generated instead
|
||||
}.invoke(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
val Int.getter: Int
|
||||
get() {
|
||||
val extFun = { Int.() ->
|
||||
val extFun: Int.() -> Int = {
|
||||
this@getter
|
||||
}
|
||||
return this@getter.extFun()
|
||||
@@ -10,7 +10,7 @@ val Int.getter: Int
|
||||
var Int.setter: Int
|
||||
get() = 1
|
||||
set(i: Int) {
|
||||
val extFun = { Int.() ->
|
||||
val extFun: Int.() -> Int = {
|
||||
this@setter
|
||||
}
|
||||
this@setter.extFun()
|
||||
|
||||
@@ -10,13 +10,13 @@ fun assertGenericSuper(expected: String, function: Any?) {
|
||||
|
||||
val unitFun = { }
|
||||
val intFun = { 42 }
|
||||
val stringParamFun = { (x: String) : Unit -> }
|
||||
val listFun = { (l: List<String>) : List<String> -> l }
|
||||
val mutableListFun = { (l: MutableList<Double>) : MutableList<Int> -> null!! }
|
||||
val funWithIn = { (x: Comparable<String>) : Unit -> }
|
||||
val stringParamFun = { x: String -> }
|
||||
val listFun = { l: List<String> -> l }
|
||||
val mutableListFun = fun (l: MutableList<Double>): MutableList<Int> = null!!
|
||||
val funWithIn = fun (x: Comparable<String>) {}
|
||||
|
||||
val extensionFun = { Any.() : Unit -> }
|
||||
val extensionWithArgFun = { Long.(x: Any) : Date -> Date() }
|
||||
val extensionFun = fun Any.() {}
|
||||
val extensionWithArgFun = fun Long.(x: Any): Date = Date()
|
||||
|
||||
fun box(): String {
|
||||
assertGenericSuper("kotlin.Function0<kotlin.Unit>", unitFun)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
fun box(): String {
|
||||
val sum = {Int.(other: Int) -> this + other }
|
||||
val sum = fun Int.(other: Int) = this + other
|
||||
return if (1 sum 2 == 3) "OK" else "Fail"
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ fun test2() {
|
||||
}
|
||||
|
||||
fun Int.foo(a: Int) = this * a
|
||||
val boo = {Int.(a: Int): Int -> this + a}
|
||||
val boo = fun Int.(a: Int): Int = this + a
|
||||
|
||||
fun box(): String {
|
||||
test1()
|
||||
|
||||
Reference in New Issue
Block a user