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 {
|
||||
fooBoxTest();
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -79,9 +79,11 @@ public class LiteralFunctionTranslator extends AbstractTranslator {
|
||||
outerClass = (ClassDescriptor) descriptor.getContainingDeclaration().getContainingDeclaration();
|
||||
assert outerClass != null;
|
||||
|
||||
if (receiverDescriptor == null) {
|
||||
aliasingContext = context().aliasingContext().notShareableThisAliased(outerClass, new JsNameRef("o", jsFunction.getName().makeRef()));
|
||||
if (aliasingContext == null) {
|
||||
aliasingContext = context().aliasingContext();
|
||||
}
|
||||
|
||||
aliasingContext = aliasingContext.notShareableThisAliased(outerClass, new JsNameRef("o", jsFunction.getName().makeRef()));
|
||||
}
|
||||
else {
|
||||
outerClass = null;
|
||||
|
||||
@@ -1,18 +1,60 @@
|
||||
// KT-2388
|
||||
package foo
|
||||
|
||||
var done = false
|
||||
var done = 0
|
||||
|
||||
object foo {
|
||||
var timeoutId: Long = 1
|
||||
var result = "FAIL"
|
||||
|
||||
val callbackWrapper = {
|
||||
timeoutId = -1 as Long
|
||||
done = true
|
||||
val lambda = {
|
||||
result = "foo.lambda OK"
|
||||
done = 3
|
||||
}
|
||||
|
||||
val extLambda: Int.()->Unit = {
|
||||
result = "foo.extLambda OK"
|
||||
done = this
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
foo.callbackWrapper()
|
||||
return foo.timeoutId == -1 as Long
|
||||
class Foo {
|
||||
var result = "FAIL"
|
||||
|
||||
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