Fix JS compiler crash when translating external object fun with vararg

See KT-19793
This commit is contained in:
Alexey Andreev
2017-09-04 12:50:57 +03:00
parent 989cebe79e
commit 5a984a40e6
4 changed files with 34 additions and 0 deletions
@@ -6191,6 +6191,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
doTest(fileName);
}
@TestMetadata("objectFunWithVararg.kt")
public void testObjectFunWithVararg() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/native/objectFunWithVararg.kt");
doTest(fileName);
}
@TestMetadata("overrideNativeOverloadedFunction.kt")
public void testOverrideNativeOverloadedFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/native/overrideNativeOverloadedFunction.kt");
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.js.translate.utils.TranslationUtils
import org.jetbrains.kotlin.js.translate.utils.getReferenceToJsClass
import org.jetbrains.kotlin.psi.Call
import org.jetbrains.kotlin.psi.ValueArgument
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
@@ -150,6 +151,11 @@ class CallArgumentTranslator private constructor(
cachedReceiver = context().getOrDeclareTemporaryConstVariable(receiver)
result.add(0, cachedReceiver.reference())
}
else if (DescriptorUtils.isObject(resolvedCall.resultingDescriptor.containingDeclaration)) {
cachedReceiver = context().getOrDeclareTemporaryConstVariable(
ReferenceTranslator.translateAsValueReference(resolvedCall.resultingDescriptor.containingDeclaration, context()))
result.add(0, cachedReceiver.reference())
}
else {
result.add(0, JsNullLiteral())
}
@@ -0,0 +1,9 @@
Test = {
test: function() {
var sum = 0;
for (var i = 0; i < arguments.length; ++i) {
sum += arguments[i];
}
return sum;
}
};
@@ -0,0 +1,13 @@
// EXPECTED_REACHABLE_NODES: 995
import Test.test
external object Test {
fun test(vararg rest: Int): Int
}
fun box(): String {
val result = test(23, 42)
if (result != 65) return "fail: $result"
return "OK"
}