JS backend: fixed bug when explicitly use invoke method in function literal call.
(cherry picked from commit f832cee)
This commit is contained in:
+5
-2
@@ -16,9 +16,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.k2js.test.semantics;
|
package org.jetbrains.k2js.test.semantics;
|
||||||
|
|
||||||
public final class InvokeMethodTest extends AbstractExpressionTest {
|
public final class InvokeConventionTest extends AbstractExpressionTest {
|
||||||
|
|
||||||
public InvokeMethodTest() {
|
public InvokeConventionTest() {
|
||||||
super("invoke/");
|
super("invoke/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,4 +27,7 @@ public final class InvokeMethodTest extends AbstractExpressionTest {
|
|||||||
// fooBoxIsValue("hello world!");
|
// fooBoxIsValue("hello world!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testExplicitInvokeLambda() throws Exception {
|
||||||
|
checkFooBoxIsOk();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+6
-3
@@ -158,15 +158,18 @@ public final class TopLevelFIF extends CompositeFIF {
|
|||||||
@NotNull TranslationContext context
|
@NotNull TranslationContext context
|
||||||
) {
|
) {
|
||||||
JsExpression thisExpression = callTranslator.getCallParameters().getThisObject();
|
JsExpression thisExpression = callTranslator.getCallParameters().getThisObject();
|
||||||
|
JsExpression functionReference = callTranslator.getCallParameters().getFunctionReference();
|
||||||
if (thisExpression == null) {
|
if (thisExpression == null) {
|
||||||
return new JsInvocation(callTranslator.getCallParameters().getFunctionReference(), arguments);
|
return new JsInvocation(functionReference, arguments);
|
||||||
}
|
}
|
||||||
else if (callTranslator.getResolvedCall().getReceiverArgument().exists()) {
|
else if (callTranslator.getResolvedCall().getReceiverArgument().exists()) {
|
||||||
return callTranslator.extensionFunctionCall(false);
|
return callTranslator.extensionFunctionCall(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new JsInvocation(new JsNameRef("call", callTranslator.getCallParameters().getFunctionReference()),
|
if (functionReference instanceof JsNameRef && ((JsNameRef) functionReference).getIdent().equals("invoke")) {
|
||||||
generateInvocationArguments(thisExpression, arguments));
|
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());
|
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
|
@NotNull
|
||||||
public JsExpression extensionFunctionCall(final boolean useThis) {
|
public JsExpression extensionFunctionCall(final boolean useThis) {
|
||||||
return callType.constructCall(callParameters.getReceiver(), new CallType.CallConstructor() {
|
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")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user