JS backend: added regression tests for closure bugs.

#KT-4236 In Progress
#KT-4600 In Progress
#KT-4237 In Progress
#KT-4207 In Progress
#KT-4218 In Progress
#KT-4263 Obsolete
This commit is contained in:
Zalim Bashorov
2014-03-06 14:35:13 +04:00
parent a48dc25c46
commit fb7165c7fa
6 changed files with 114 additions and 0 deletions
@@ -143,4 +143,24 @@ public final class ClosureTest extends SingleFileTranslationTest {
public void testClosureInFewFunctionWithDifferentName() throws Exception {
checkFooBoxIsOk();
}
public void testClosureLambdaVarInLambda() throws Exception {
checkFooBoxIsOk();
}
public void testClosureThisInExtLambdaInsideMethod() throws Exception {
checkFooBoxIsOk();
}
public void testClosureInWithInsideWith() throws Exception {
checkFooBoxIsOk();
}
public void testClosureInNestedLambdasInObject() throws Exception {
checkFooBoxIsOk();
}
public void testClosureThisInLambdaInsideMethod() throws Exception {
checkFooBoxIsOk();
}
}
@@ -0,0 +1,18 @@
// KT-4218 Nested function literal on singleton object fails
package foo
object SomeObject {
val values = create()
fun create() = Array<Array<String>>(1) { y ->
Array<String>(1) { x ->
"(${x}, ${y})"
}
}
}
fun box(): String {
if (SomeObject.values[0][0] != "(0, 0)") return SomeObject.values[0][0]
return "OK"
}
@@ -0,0 +1,25 @@
// KT-4237 With in with
package foo
class A {
val ok = "OK"
}
class B
fun with<T>(o: T, body: T.() -> Unit) {
o.body()
}
fun box(): String {
var o = ""
with(A()) {
with(B()) {
o = ok
}
}
return o
}
@@ -0,0 +1,23 @@
// KT-4263 Wrong capturing a function literal variable
package foo
fun assertEquals<T>(expected: T, actual: T) {
if (expected != actual) throw Exception("expected = $expected, actual = $actual")
}
fun box(): String {
var foo = { 1 }
var bar = 1
val t = { "${foo()} $bar" }
fun b() = "${foo()} $bar"
foo = { 2 }
bar = 2
assertEquals("2 2", t())
assertEquals("2 2", b())
return "OK"
}
@@ -0,0 +1,11 @@
// KT-4600 Generated wrong code when capturing `this` in extension function inside a method
package foo
fun run<T>(f: Int.() -> T) = 1.f()
public class Foo(val trigger: () -> Any) {
fun test() = run {trigger()};
}
fun box() = Foo({ "OK" }).test()
@@ -0,0 +1,17 @@
// KT-4207 Closure this doesn't work in JS backend
package foo
fun String.foo() = { this }
class A {
fun foo() = { this }
val ok = "OK"
}
fun box(): String {
if ("OK".foo()() != "OK") return "\"OK\".foo()() != \"OK\""
if (A().foo()().ok != "OK") return "A().foo()().ok != \"OK\""
return "OK"
}