JS backend: fix closure this in extension (literal) function.
This commit is contained in:
@@ -70,6 +70,6 @@ public final class ClosureTest extends SingleFileTranslationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testClosureThisInConstructor() throws Exception {
|
public void testClosureThisInConstructor() throws Exception {
|
||||||
fooBoxTest();
|
checkFooBoxIsOk();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -79,9 +79,11 @@ public class LiteralFunctionTranslator extends AbstractTranslator {
|
|||||||
outerClass = (ClassDescriptor) descriptor.getContainingDeclaration().getContainingDeclaration();
|
outerClass = (ClassDescriptor) descriptor.getContainingDeclaration().getContainingDeclaration();
|
||||||
assert outerClass != null;
|
assert outerClass != null;
|
||||||
|
|
||||||
if (receiverDescriptor == null) {
|
if (aliasingContext == null) {
|
||||||
aliasingContext = context().aliasingContext().notShareableThisAliased(outerClass, new JsNameRef("o", jsFunction.getName().makeRef()));
|
aliasingContext = context().aliasingContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aliasingContext = aliasingContext.notShareableThisAliased(outerClass, new JsNameRef("o", jsFunction.getName().makeRef()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
outerClass = null;
|
outerClass = null;
|
||||||
|
|||||||
@@ -1,18 +1,60 @@
|
|||||||
// KT-2388
|
// KT-2388
|
||||||
package foo
|
package foo
|
||||||
|
|
||||||
var done = false
|
var done = 0
|
||||||
|
|
||||||
object foo {
|
object foo {
|
||||||
var timeoutId: Long = 1
|
var result = "FAIL"
|
||||||
|
|
||||||
val callbackWrapper = {
|
val lambda = {
|
||||||
timeoutId = -1 as Long
|
result = "foo.lambda OK"
|
||||||
done = true
|
done = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
val extLambda: Int.()->Unit = {
|
||||||
|
result = "foo.extLambda OK"
|
||||||
|
done = this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun box(): Boolean {
|
class Foo {
|
||||||
foo.callbackWrapper()
|
var result = "FAIL"
|
||||||
return foo.timeoutId == -1 as Long
|
|
||||||
|
val lambda = {
|
||||||
|
result = "Foo::lambda OK"
|
||||||
|
done = -7
|
||||||
|
}
|
||||||
|
|
||||||
|
val extLambda: Int.()->Unit = {
|
||||||
|
result = "Foo::extLambda OK"
|
||||||
|
done = this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a = foo.lambda
|
||||||
|
val b = foo.extLambda
|
||||||
|
|
||||||
|
val f = Foo()
|
||||||
|
val c = f.lambda
|
||||||
|
val d = f.extLambda
|
||||||
|
|
||||||
|
a()
|
||||||
|
if (foo.result != "foo.lambda OK") return "foo.result = \"${foo.result}\", but expected \"foo.lambda OK\""
|
||||||
|
if (done != 3) return "done = $done, but expected 3"
|
||||||
|
|
||||||
|
23.b()
|
||||||
|
if (foo.result != "foo.extLambda OK") return "foo.result = \"${foo.result}\", but expected \"foo.extLambda OK\""
|
||||||
|
if (done != 23) return "done = $done, but expected 23"
|
||||||
|
|
||||||
|
|
||||||
|
c()
|
||||||
|
if (f.result != "Foo::lambda OK") return "a.result = \"${f.result}\", but expected \"Foo::lambda OK\""
|
||||||
|
if (done != -7) return "done = $done, but expected -7"
|
||||||
|
|
||||||
|
71.d()
|
||||||
|
if (f.result != "Foo::extLambda OK") return "a.result = \"${f.result}\", but expected \"Foo::extLambda OK\""
|
||||||
|
if (done != 71) return "done = $done, but expected 71"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user