Analyze Data Flow: Support lambdas/anonymous functions

#KT-11994 In Progress
This commit is contained in:
Alexey Sedunov
2017-05-31 21:31:23 +03:00
parent 0f44dd6ab0
commit 3f411fc93b
40 changed files with 494 additions and 29 deletions
@@ -0,0 +1,9 @@
// FLOW: IN
fun foo(f: (Int) -> Int): Int {
return f(1)
}
fun test() {
val <caret>x = foo(fun(n: Int) = n)
}
@@ -0,0 +1,10 @@
8 val <bold>x = foo(fun(n: Int) = n)</bold>
8 val x = <bold>foo(fun(n: Int) = n)</bold>
3 fun <bold>foo(f: (Int) -> Int): Int {</bold>
4 return <bold>f(1)</bold>
4 [LAMBDA] return <bold>f</bold>(1)
3 [LAMBDA] fun foo(<bold>f: (Int) -> Int</bold>): Int {
8 [LAMBDA] val x = foo(<bold>fun(n: Int) = n</bold>)
8 val x = foo(<bold>fun(n: Int) = n</bold>)
8 val x = foo(fun(n: Int) = <bold>n</bold>)
8 val x = foo(fun(<bold>n: Int</bold>) = n)
@@ -0,0 +1,9 @@
// FLOW: IN
fun foo(f: (Int) -> Int): Int {
return f(1)
}
fun test() {
val <caret>x = foo(fun(n: Int): Int { return n })
}
@@ -0,0 +1,10 @@
8 val <bold>x = foo(fun(n: Int): Int { return n })</bold>
8 val x = <bold>foo(fun(n: Int): Int { return n })</bold>
3 fun <bold>foo(f: (Int) -> Int): Int {</bold>
4 return <bold>f(1)</bold>
4 [LAMBDA] return <bold>f</bold>(1)
3 [LAMBDA] fun foo(<bold>f: (Int) -> Int</bold>): Int {
8 [LAMBDA] val x = foo(<bold>fun(n: Int): Int { return n }</bold>)
8 val x = foo(<bold>fun(n: Int): Int { return n }</bold>)
8 val x = foo(fun(n: Int): Int { return <bold>n</bold> })
8 val x = foo(fun(<bold>n: Int</bold>): Int { return n })
+9
View File
@@ -0,0 +1,9 @@
// FLOW: IN
fun foo(a: Int, b: Int, f: (Int) -> (Int) -> Int): Int {
return f(a)(b)
}
fun test() {
val <caret>x = foo(1, 2) { { it } }
}
@@ -0,0 +1,12 @@
8 val <bold>x = foo(1, 2) { { it } }</bold>
8 val x = <bold>foo(1, 2) { { it } }</bold>
3 fun <bold>foo(a: Int, b: Int, f: (Int) -> (Int) -> Int): Int {</bold>
4 return <bold>f(a)(b)</bold>
4 [LAMBDA] return <bold>f(a)</bold>(b)
4 [LAMBDA] [LAMBDA] return <bold>f</bold>(a)(b)
3 [LAMBDA] [LAMBDA] fun foo(a: Int, b: Int, <bold>f: (Int) -> (Int) -> Int</bold>): Int {
8 [LAMBDA] [LAMBDA] val x = foo(1, 2) <bold>{ { it } }</bold>
8 [LAMBDA] val x = foo(1, 2) <bold>{ { it } }</bold>
8 [LAMBDA] val x = foo(1, 2) { <bold>{ it }</bold> }
8 val x = foo(1, 2) { <bold>{ it }</bold> }
8 val x = foo(1, 2) { { <bold>it</bold> } }
+9
View File
@@ -0,0 +1,9 @@
// FLOW: IN
fun foo(f: (Int) -> Int): Int {
return f(1)
}
fun test() {
val <caret>x = foo { it }
}
+9
View File
@@ -0,0 +1,9 @@
8 val <bold>x = foo { it }</bold>
8 val x = <bold>foo { it }</bold>
3 fun <bold>foo(f: (Int) -> Int): Int {</bold>
4 return <bold>f(1)</bold>
4 [LAMBDA] return <bold>f</bold>(1)
3 [LAMBDA] fun foo(<bold>f: (Int) -> Int</bold>): Int {
8 [LAMBDA] val x = foo <bold>{ it }</bold>
8 val x = foo <bold>{ it }</bold>
8 val x = foo { <bold>it</bold> }
@@ -0,0 +1,10 @@
// FLOW: IN
fun foo(f: (Int) -> Int): Int {
val x = f
return x(1)
}
fun test() {
val <caret>y = foo { it }
}
@@ -0,0 +1,11 @@
9 val <bold>y = foo { it }</bold>
9 val y = <bold>foo { it }</bold>
3 fun <bold>foo(f: (Int) -> Int): Int {</bold>
5 return <bold>x(1)</bold>
5 [LAMBDA] return <bold>x</bold>(1)
4 [LAMBDA] val <bold>x = f</bold>
4 [LAMBDA] val x = <bold>f</bold>
3 [LAMBDA] fun foo(<bold>f: (Int) -> Int</bold>): Int {
9 [LAMBDA] val y = foo <bold>{ it }</bold>
9 val y = foo <bold>{ it }</bold>
9 val y = foo { <bold>it</bold> }
@@ -0,0 +1,5 @@
// FLOW: IN
fun test() {
val <caret>x = { 1 }()
}
@@ -0,0 +1,5 @@
4 val <bold>x = { 1 }()</bold>
4 val x = <bold>{ 1 }()</bold>
4 [LAMBDA] val x = <bold>{ 1 }</bold>()
4 val x = <bold>{ 1 }</bold>()
4 val x = { <bold>1</bold> }()
@@ -0,0 +1,6 @@
// FLOW: IN
fun test() {
val f = { 1 }
val <caret>x = f()
}
@@ -0,0 +1,7 @@
5 val <bold>x = f()</bold>
5 val x = <bold>f()</bold>
5 [LAMBDA] val x = <bold>f</bold>()
4 [LAMBDA] val <bold>f = { 1 }</bold>
4 [LAMBDA] val f = <bold>{ 1 }</bold>
4 val f = <bold>{ 1 }</bold>
4 val f = { <bold>1</bold> }
+5
View File
@@ -0,0 +1,5 @@
// FLOW: IN
inline fun foo(a: Int, f: (Int) -> Int) = f(a)
fun <caret>bar(a: Int): Int = foo(a) { if (it > 0) it else return 0 }
+11
View File
@@ -0,0 +1,11 @@
5 fun <bold>bar(a: Int): Int = foo(a) { if (it > 0) it else return 0 }</bold>
5 fun bar(a: Int): Int = foo(a) { if (it > 0) it else return <bold>0</bold> }
5 fun bar(a: Int): Int = <bold>foo(a) { if (it > 0) it else return 0 }</bold>
3 inline fun <bold>foo(a: Int, f: (Int) -> Int) = f(a)</bold>
3 inline fun foo(a: Int, f: (Int) -> Int) = <bold>f(a)</bold>
3 [LAMBDA] inline fun foo(a: Int, f: (Int) -> Int) = <bold>f</bold>(a)
3 [LAMBDA] inline fun foo(a: Int, <bold>f: (Int) -> Int</bold>) = f(a)
5 [LAMBDA] fun bar(a: Int): Int = foo(a) <bold>{ if (it > 0) it else return 0 }</bold>
5 fun bar(a: Int): Int = foo(a) <bold>{ if (it > 0) it else return 0 }</bold>
5 fun bar(a: Int): Int = foo(a) { <bold>if (it > 0) it else return 0</bold> }
5 fun bar(a: Int): Int = foo(a) { if (it > 0) <bold>it</bold> else return 0 }