KT-12877: fix how native calls and property references are translated to be make them work with JsModule annotation
This commit is contained in:
committed by
Alexey Andreev
parent
ac703dfda6
commit
b1d8f91212
+1
-2
@@ -82,8 +82,7 @@ object CallTranslator {
|
|||||||
return DefaultFunctionCallCase.buildDefaultCallWithDispatchReceiver(argumentsInfo, dispatchReceiver, functionName, isNative,
|
return DefaultFunctionCallCase.buildDefaultCallWithDispatchReceiver(argumentsInfo, dispatchReceiver, functionName, isNative,
|
||||||
hasSpreadOperator)
|
hasSpreadOperator)
|
||||||
} else {
|
} else {
|
||||||
return DefaultFunctionCallCase.buildDefaultCallWithoutReceiver(context, argumentsInfo, functionDescriptor, isNative,
|
return DefaultFunctionCallCase.buildDefaultCallWithoutReceiver(context, argumentsInfo, functionDescriptor, isNative, hasSpreadOperator)
|
||||||
hasSpreadOperator)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -59,7 +59,7 @@ object NativeVariableAccessCase : VariableAccessCase() {
|
|||||||
JsInvocation(methodRef, *additionalArguments.toTypedArray())
|
JsInvocation(methodRef, *additionalArguments.toTypedArray())
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
constructAccessExpression(variableName.makeRef())
|
constructAccessExpression(context.getQualifiedReference(callableDescriptor))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,19 +235,7 @@ public final class StaticContext {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsExpression buildQualifiedExpression(@NotNull DeclarationDescriptor descriptor) {
|
private JsExpression buildQualifiedExpression(@NotNull DeclarationDescriptor descriptor) {
|
||||||
String moduleName = AnnotationsUtils.getModuleName(descriptor);
|
if (descriptor instanceof ClassDescriptor) {
|
||||||
if (moduleName != null) {
|
|
||||||
return JsAstUtils.pureFqn(getModuleInternalName(moduleName), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNativeObject(descriptor)) {
|
|
||||||
String fileModuleName = AnnotationsUtils.getFileModuleName(getBindingContext(), descriptor);
|
|
||||||
if (fileModuleName != null) {
|
|
||||||
return pureFqn(getNameForDescriptor(descriptor), pureFqn(getModuleInternalName(fileModuleName), null));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (descriptor instanceof ClassDescriptor) {
|
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
|
ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
|
||||||
if (KotlinBuiltIns.isAny(classDescriptor)) {
|
if (KotlinBuiltIns.isAny(classDescriptor)) {
|
||||||
return pureFqn("Object", null);
|
return pureFqn("Object", null);
|
||||||
@@ -261,6 +249,18 @@ public final class StaticContext {
|
|||||||
return result != null ? result : pureFqn(Namer.getRootPackageName(), null);
|
return result != null ? result : pureFqn(Namer.getRootPackageName(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String moduleName = AnnotationsUtils.getModuleName(suggested.getDescriptor());
|
||||||
|
if (moduleName != null) {
|
||||||
|
return JsAstUtils.pureFqn(getModuleInternalName(moduleName), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNativeObject(suggested.getDescriptor())) {
|
||||||
|
String fileModuleName = AnnotationsUtils.getFileModuleName(getBindingContext(), suggested.getDescriptor());
|
||||||
|
if (fileModuleName != null) {
|
||||||
|
return pureFqn(getNameForDescriptor(suggested.getDescriptor()), pureFqn(getModuleInternalName(fileModuleName), null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
JsExpression expression;
|
JsExpression expression;
|
||||||
List<JsName> partNames = getActualNameFromSuggested(suggested);
|
List<JsName> partNames = getActualNameFromSuggested(suggested);
|
||||||
if (isLibraryObject(suggested.getDescriptor())) {
|
if (isLibraryObject(suggested.getDescriptor())) {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ fun box(): String {
|
|||||||
assertEquals(123, B.x)
|
assertEquals(123, B.x)
|
||||||
assertEquals(265, B.foo(142))
|
assertEquals(265, B.foo(142))
|
||||||
|
|
||||||
assertEquals(365, foo(23))
|
assertEquals(365, foo(42))
|
||||||
assertEquals(423, bar)
|
assertEquals(423, bar)
|
||||||
|
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ fun box(): String {
|
|||||||
assertEquals(123, B.x)
|
assertEquals(123, B.x)
|
||||||
assertEquals(265, B.foo(142))
|
assertEquals(265, B.foo(142))
|
||||||
|
|
||||||
assertEquals(365, foo(23))
|
assertEquals(365, foo(42))
|
||||||
assertEquals(423, bar)
|
assertEquals(423, bar)
|
||||||
|
|
||||||
assertEquals(12345, C.f())
|
assertEquals(12345, C.f())
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ fun box(): String {
|
|||||||
assertEquals(123, B.x)
|
assertEquals(123, B.x)
|
||||||
assertEquals(265, B.foo(142))
|
assertEquals(265, B.foo(142))
|
||||||
|
|
||||||
assertEquals(365, foo(23))
|
assertEquals(365, foo(42))
|
||||||
assertEquals(423, bar)
|
assertEquals(423, bar)
|
||||||
|
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
@file:JsModule("lib")
|
||||||
|
package foo
|
||||||
|
|
||||||
|
@native class A(@native val x: Int = noImpl) {
|
||||||
|
@native fun foo(y: Int): Int = noImpl
|
||||||
|
}
|
||||||
|
|
||||||
|
@native object B {
|
||||||
|
@native val x: Int = noImpl
|
||||||
|
|
||||||
|
@native fun foo(y: Int): Int = noImpl
|
||||||
|
}
|
||||||
|
|
||||||
|
@native fun foo(y: Int): Int = noImpl
|
||||||
|
|
||||||
|
@native val bar: Int = noImpl
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a = A(23)
|
||||||
|
assertEquals(23, a.x)
|
||||||
|
assertEquals(65, a.foo(42))
|
||||||
|
|
||||||
|
assertEquals(123, B.x)
|
||||||
|
assertEquals(265, B.foo(142))
|
||||||
|
|
||||||
|
assertEquals(365, foo(42))
|
||||||
|
assertEquals(423, bar)
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a = A(23)
|
||||||
|
assertEquals(23, a.x)
|
||||||
|
assertEquals(65, a.foo(42))
|
||||||
|
|
||||||
|
assertEquals(123, B.x)
|
||||||
|
assertEquals(265, B.foo(142))
|
||||||
|
|
||||||
|
assertEquals(365, foo(42))
|
||||||
|
assertEquals(423, bar)
|
||||||
|
|
||||||
|
assertEquals(12345, C.f())
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+2
-3
@@ -8,9 +8,8 @@ fun box(): String {
|
|||||||
assertEquals(123, B.x)
|
assertEquals(123, B.x)
|
||||||
assertEquals(265, B.foo(142))
|
assertEquals(265, B.foo(142))
|
||||||
|
|
||||||
/* TODO: get rid of usages of getQualifier, then uncomment it (it's already fixed by js-name branch)
|
assertEquals(365, foo(42))
|
||||||
assertEquals(365, foo(23))
|
assertEquals(423, bar)
|
||||||
assertEquals(423, bar)*/
|
|
||||||
|
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user