Introduce Variable: Allow choosing extraction scope for expressions in the lambda body

#KT-7720 Fixed
This commit is contained in:
Alexey Sedunov
2015-11-13 15:06:34 +03:00
parent 70049171cd
commit 5889971d62
25 changed files with 334 additions and 16 deletions
@@ -0,0 +1,9 @@
class A(val a: Int)
class B(val b: Int)
fun foo(f: A.() -> Int) = A(1).f()
fun bar(f: B.() -> Int) = B(2).f()
fun test() {
foo { bar { <selection>a</selection> + b } }
}
@@ -0,0 +1,10 @@
class A(val a: Int)
class B(val b: Int)
fun foo(f: A.() -> Int) = A(1).f()
fun bar(f: B.() -> Int) = B(2).f()
fun test() {
foo { val a1 = a
bar { a1 + b } }
}
@@ -0,0 +1,9 @@
class A(val a: Int)
class B(val b: Int)
fun foo(f: A.() -> Int) = A(1).f()
fun bar(f: B.() -> Int) = B(2).f()
fun test() {
foo { bar { a + <selection>b</selection> } }
}
@@ -0,0 +1,11 @@
class A(val a: Int)
class B(val b: Int)
fun foo(f: A.() -> Int) = A(1).f()
fun bar(f: B.() -> Int) = B(2).f()
fun test() {
foo { bar { val b1 = b
a + b1
} }
}
@@ -0,0 +1,5 @@
fun foo(f: () -> Int) { }
fun test() {
foo(fun() = (<selection>1 + 2</selection>) * 3)
}
@@ -0,0 +1,6 @@
fun foo(f: () -> Int) { }
fun test() {
val i = 1 + 2
foo(fun() = i * 3)
}
@@ -0,0 +1,5 @@
fun foo(f: () -> Int) { }
fun test() {
foo(fun(): Int { return (<selection>1 + 2</selection>) * 3 })
}
@@ -0,0 +1,6 @@
fun foo(f: () -> Int) { }
fun test() {
val i = 1 + 2
foo(fun(): Int { return i * 3 })
}
@@ -0,0 +1,5 @@
fun foo(f: () -> Int) { }
fun test() {
foo { (<selection>1 + 2</selection>) * 3 }
}
@@ -0,0 +1,6 @@
fun foo(f: () -> Int) { }
fun test() {
val i = 1 + 2
foo { i * 3 }
}
@@ -0,0 +1,5 @@
fun foo(f: () -> Int) = f()
fun test() {
foo(fun() = foo(fun() = (<selection>1 + 2</selection>) * 3))
}
@@ -0,0 +1,6 @@
fun foo(f: () -> Int) = f()
fun test() {
val i = 1 + 2
foo(fun() = foo(fun() = i * 3))
}
@@ -0,0 +1,5 @@
fun foo(f: () -> Int) = f()
fun test() {
foo { foo(fun() = (<selection>1 + 2</selection>) * 3) }
}
@@ -0,0 +1,6 @@
fun foo(f: () -> Int) = f()
fun test() {
val i = 1 + 2
foo { foo(fun() = i * 3) }
}
@@ -0,0 +1,5 @@
fun foo(f: () -> Int) = f()
fun test() {
foo { foo { (<selection>1 + 2</selection>) * 3 } }
}
@@ -0,0 +1,6 @@
fun foo(f: () -> Int) = f()
fun test() {
val i = 1 + 2
foo { foo { i * 3 } }
}
@@ -0,0 +1,5 @@
fun foo(f: () -> Int) = f()
fun test() {
foo(fun() = foo { (<selection>1 + 2</selection>) * 3 })
}
@@ -0,0 +1,6 @@
fun foo(f: () -> Int) = f()
fun test() {
val i = 1 + 2
foo(fun() = foo { i * 3 })
}
@@ -0,0 +1,5 @@
fun foo(f: (Int) -> Int) = f(0)
fun test() {
foo { foo { (1 + 2) * <selection>it</selection> } }
}
@@ -0,0 +1,7 @@
fun foo(f: (Int) -> Int) = f(0)
fun test() {
foo { foo { val it1 = it
(1 + 2) * it1
} }
}
@@ -0,0 +1,6 @@
fun foo(f: (Int) -> Int) = f(0)
fun bar(f: () -> Int) = f()
fun test() {
foo { bar { (1 + 2) * <selection>it</selection> } }
}
@@ -0,0 +1,7 @@
fun foo(f: (Int) -> Int) = f(0)
fun bar(f: () -> Int) = f()
fun test() {
foo { val it1 = it
bar { (1 + 2) * it1 } }
}