JS backend: fixed bug when call native function with custom name using spread operator.
This commit is contained in:
+3
-2
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.k2js.translate.reference;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import com.google.dart.compiler.backend.js.ast.JsName;
|
||||
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -102,8 +103,8 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
|
||||
private JsExpression getCalleeExpression() {
|
||||
assert argumentsInfo != null : "the results of this function depends on the argumentsInfo";
|
||||
if (isNativeFunctionCall && argumentsInfo.isHasSpreadOperator()) {
|
||||
String functionName = resolvedCall.getCandidateDescriptor().getOriginal().getName().getIdentifier();
|
||||
return new JsNameRef("apply", functionName);
|
||||
JsName functionName = context().getNameForDescriptor(resolvedCall.getCandidateDescriptor());
|
||||
return new JsNameRef("apply", functionName.makeRef());
|
||||
}
|
||||
CallableDescriptor candidateDescriptor = resolvedCall.getCandidateDescriptor();
|
||||
if (candidateDescriptor instanceof ExpressionAsFunctionDescriptor) {
|
||||
|
||||
@@ -5,9 +5,15 @@ import js.*
|
||||
native
|
||||
fun paramCount(vararg a : Int) : Int = js.noImpl
|
||||
|
||||
native("paramCount")
|
||||
fun anotherParamCount(vararg a : Int) : Int = js.noImpl
|
||||
|
||||
// test spread operator
|
||||
fun count(vararg a : Int) = paramCount(*a)
|
||||
|
||||
// test spread operator
|
||||
fun anotherCount(vararg a : Int) = anotherParamCount(*a)
|
||||
|
||||
native
|
||||
class Bar(val size: Int, order: Int = 0) {
|
||||
fun test(order: Int, dummy: Int, vararg args: Int): Boolean = js.noImpl
|
||||
@@ -49,12 +55,18 @@ fun box(): String {
|
||||
if (paramCount(1, 2 ,3) != 3)
|
||||
return "failed when call native function with some args"
|
||||
|
||||
if (anotherParamCount(1, 2 ,3) != 3)
|
||||
return "failed when call native function with some args witch declareted with custom name"
|
||||
|
||||
if (count() != 0)
|
||||
return "failed when call native function without args using spread operator"
|
||||
|
||||
if (count(1, 1, 1, 1) != 4)
|
||||
return "failed when call native function with some args using spread operator"
|
||||
|
||||
if (anotherCount(1, 2 ,3) != 3)
|
||||
return "failed when call native function with some args using spread operator witch declareted with custom name"
|
||||
|
||||
if (!Bar(5).test(0, 1, 1, 2, 3, 4, 5))
|
||||
return "failed when call method with some args"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user