KT-1519: Error calling native extension function from user defined extension function.
This commit is contained in:
@@ -62,4 +62,8 @@ public final class ExtensionFunctionTest extends SingleFileTranslationTest {
|
||||
public void testGenericExtension() throws Exception {
|
||||
checkFooBoxIsOk("generic.kt");
|
||||
}
|
||||
|
||||
public void testExtensionFunctionCalledFromExtensionFunction() throws Exception {
|
||||
checkFooBoxIsTrue("extensionFunctionCalledFromExtensionFunction.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,4 +57,8 @@ public final class NativeInteropTest extends SingleFileTranslationTest {
|
||||
public void testUndefined() throws Exception {
|
||||
checkFooBoxIsTrue("undefined.kt");
|
||||
}
|
||||
|
||||
public void testKt1519() throws Exception {
|
||||
checkFooBoxIsTrue("KT-1519.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import static org.jetbrains.k2js.translate.utils.TranslationUtils.getThisObject;
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
//TODO: write tests on calling backing fields as functions
|
||||
//TODO: refactor call parameters to be used across the class
|
||||
public final class CallTranslator extends AbstractTranslator {
|
||||
|
||||
private static class CallParameters {
|
||||
@@ -95,15 +96,15 @@ public final class CallTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
/*package*/ JsExpression translate() {
|
||||
//NOTE: treat native extension function calls as usual calls
|
||||
if (isIntrinsic()) {
|
||||
return intrinsicInvocation();
|
||||
}
|
||||
if (isConstructor()) {
|
||||
return constructorCall();
|
||||
}
|
||||
if (isNative()) {
|
||||
return methodCall();
|
||||
//NOTE: treat native extension function calls as usual calls
|
||||
if (isNativeExtensionFunctionCall()) {
|
||||
return nativeExtensionCall();
|
||||
}
|
||||
if (isExtensionFunctionLiteral()) {
|
||||
return extensionFunctionLiteralCall();
|
||||
@@ -114,6 +115,12 @@ public final class CallTranslator extends AbstractTranslator {
|
||||
return methodCall();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsExpression nativeExtensionCall() {
|
||||
receiver = getExtensionFunctionCallReceiver();
|
||||
return methodCall();
|
||||
}
|
||||
|
||||
private boolean isIntrinsic() {
|
||||
return context().intrinsics().isIntrinsic(descriptor);
|
||||
}
|
||||
@@ -144,8 +151,8 @@ public final class CallTranslator extends AbstractTranslator {
|
||||
return ReferenceTranslator.translateAsFQReference(descriptor, context());
|
||||
}
|
||||
|
||||
private boolean isNative() {
|
||||
return AnnotationsUtils.isNativeObject(descriptor);
|
||||
private boolean isNativeExtensionFunctionCall() {
|
||||
return AnnotationsUtils.isNativeObject(descriptor) && isExtensionFunction();
|
||||
}
|
||||
|
||||
private boolean isExtensionFunctionLiteral() {
|
||||
@@ -251,6 +258,7 @@ public final class CallTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
private CallParameters callParameters() {
|
||||
// TODO: this check corresponds to expression as function, make it clearer
|
||||
if (callee != null) {
|
||||
return new CallParameters(null, callee);
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
class A() {
|
||||
|
||||
}
|
||||
|
||||
fun A.one() = 1
|
||||
fun A.two() = one() + one()
|
||||
|
||||
fun box() : Boolean {
|
||||
return (A().two() == 2)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
native
|
||||
class Wow() {
|
||||
val x : Int = js.noImpl
|
||||
val y : Int = js.noImpl
|
||||
}
|
||||
|
||||
native
|
||||
fun Wow.sum() : Int = js.noImpl
|
||||
|
||||
fun Wow.dblSum() : Int {
|
||||
return 2 * sum()
|
||||
}
|
||||
|
||||
|
||||
fun box() : Boolean {
|
||||
return (Wow().dblSum() == 6)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function Wow() {
|
||||
this.x = 1;
|
||||
this.y = 2;
|
||||
}
|
||||
|
||||
Wow.prototype.sum = function() {
|
||||
return this.x + this.y;
|
||||
};
|
||||
Reference in New Issue
Block a user