JS backend: fixed bug when explicitly use invoke method in function literal call.

(cherry picked from commit f832cee)
This commit is contained in:
develar
2013-08-23 14:47:25 +04:00
committed by Zalim Bashorov
parent f08cb5f6ca
commit 4f9485b40e
4 changed files with 28 additions and 5 deletions
@@ -16,9 +16,9 @@
package org.jetbrains.k2js.test.semantics;
public final class InvokeMethodTest extends AbstractExpressionTest {
public final class InvokeConventionTest extends AbstractExpressionTest {
public InvokeMethodTest() {
public InvokeConventionTest() {
super("invoke/");
}
@@ -27,4 +27,7 @@ public final class InvokeMethodTest extends AbstractExpressionTest {
// fooBoxIsValue("hello world!");
}
public void testExplicitInvokeLambda() throws Exception {
checkFooBoxIsOk();
}
}
@@ -158,15 +158,18 @@ public final class TopLevelFIF extends CompositeFIF {
@NotNull TranslationContext context
) {
JsExpression thisExpression = callTranslator.getCallParameters().getThisObject();
JsExpression functionReference = callTranslator.getCallParameters().getFunctionReference();
if (thisExpression == null) {
return new JsInvocation(callTranslator.getCallParameters().getFunctionReference(), arguments);
return new JsInvocation(functionReference, arguments);
}
else if (callTranslator.getResolvedCall().getReceiverArgument().exists()) {
return callTranslator.extensionFunctionCall(false);
}
else {
return new JsInvocation(new JsNameRef("call", callTranslator.getCallParameters().getFunctionReference()),
generateInvocationArguments(thisExpression, arguments));
if (functionReference instanceof JsNameRef && ((JsNameRef) functionReference).getIdent().equals("invoke")) {
return callTranslator.explicitInvokeCall();
}
return new JsInvocation(new JsNameRef("call", functionReference), generateInvocationArguments(thisExpression, arguments));
}
}
}
@@ -149,6 +149,17 @@ public final class CallTranslator extends AbstractTranslator {
return methodCall(callParameters.getReceiver());
}
@NotNull
public JsExpression explicitInvokeCall() {
return callType.constructCall(callParameters.getThisObject(), new CallType.CallConstructor() {
@NotNull
@Override
public JsExpression construct(@Nullable JsExpression receiver) {
return new JsInvocation(receiver, arguments);
}
}, context());
}
@NotNull
public JsExpression extensionFunctionCall(final boolean useThis) {
return callType.constructCall(callParameters.getReceiver(), new CallType.CallConstructor() {
@@ -0,0 +1,6 @@
package foo
fun box() : String {
var foo = { (x: String) -> x + "K" }
return foo.invoke("O")
}