JS: extension lambdas translated same as local lambdas (KT-13312 fixed)
This commit is contained in:
+4
-20
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.js.translate.callTranslator
|
||||
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionInvokeDescriptor
|
||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.js.PredefinedAnnotation
|
||||
import org.jetbrains.kotlin.js.backend.ast.*
|
||||
@@ -101,20 +100,12 @@ object DefaultFunctionCallCase : FunctionCallCase() {
|
||||
|
||||
val functionRef = ReferenceTranslator.translateAsValueReference(callableDescriptor, context)
|
||||
|
||||
val referenceToCall =
|
||||
if (callableDescriptor.visibility == Visibilities.LOCAL) {
|
||||
Namer.getFunctionCallRef(functionRef)
|
||||
}
|
||||
else {
|
||||
functionRef
|
||||
}
|
||||
|
||||
return JsInvocation(referenceToCall, argumentsInfo.argsWithReceiver(extensionReceiver!!))
|
||||
return JsInvocation(functionRef, argumentsInfo.argsWithReceiver(extensionReceiver!!))
|
||||
}
|
||||
|
||||
override fun FunctionCallInfo.bothReceivers(): JsExpression {
|
||||
// TODO: think about crazy case: spreadOperator + native
|
||||
val functionRef = JsNameRef(functionName, dispatchReceiver!!)
|
||||
val functionRef = JsAstUtils.pureFqn(functionName, dispatchReceiver!!)
|
||||
return JsInvocation(functionRef, argumentsInfo.argsWithReceiver(extensionReceiver!!))
|
||||
}
|
||||
}
|
||||
@@ -170,14 +161,7 @@ object InvokeIntrinsic : FunctionCallCase() {
|
||||
}
|
||||
|
||||
override fun FunctionCallInfo.dispatchReceiver(): JsExpression {
|
||||
val receiver = resolvedCall.dispatchReceiver!!
|
||||
val jsReceiver = if (receiver.type.isExtensionFunctionType) {
|
||||
pureFqn(Namer.CALL_FUNCTION, dispatchReceiver)
|
||||
}
|
||||
else {
|
||||
dispatchReceiver!!
|
||||
}
|
||||
return JsInvocation(jsReceiver, argumentsInfo.translateArguments)
|
||||
return JsInvocation(dispatchReceiver!!, argumentsInfo.translateArguments)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +178,7 @@ object InvokeIntrinsic : FunctionCallCase() {
|
||||
* extLambda.call(obj, some, args)
|
||||
*/
|
||||
override fun FunctionCallInfo.bothReceivers(): JsExpression {
|
||||
return JsInvocation(Namer.getFunctionCallRef(dispatchReceiver!!), argumentsInfo.argsWithReceiver(extensionReceiver!!))
|
||||
return JsInvocation(dispatchReceiver!!, argumentsInfo.argsWithReceiver(extensionReceiver!!))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -130,7 +130,7 @@ object DefaultVariableAccessCase : VariableAccessCase() {
|
||||
}
|
||||
|
||||
override fun VariableAccessInfo.bothReceivers(): JsExpression {
|
||||
val funRef = JsNameRef(context.getNameForDescriptor(getAccessDescriptorIfNeeded()), dispatchReceiver!!)
|
||||
val funRef = JsAstUtils.pureFqn(context.getNameForDescriptor(getAccessDescriptorIfNeeded()), dispatchReceiver!!)
|
||||
return JsInvocation(funRef, extensionReceiver!!, *additionalArguments.toTypedArray())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,10 +211,6 @@ public final class Namer {
|
||||
@NotNull
|
||||
private final JsName boundCallableRefForExtensionFunctionName;
|
||||
@NotNull
|
||||
private final JsName callableRefForLocalExtensionFunctionName;
|
||||
@NotNull
|
||||
private final JsName boundCallableRefForLocalExtensionFunctionName;
|
||||
@NotNull
|
||||
private final JsName callableRefForConstructorName;
|
||||
@NotNull
|
||||
private final JsName callableRefForTopLevelProperty;
|
||||
@@ -244,8 +240,6 @@ public final class Namer {
|
||||
boundCallableRefForMemberFunctionName = kotlinScope.declareName(BOUND_CALLABLE_REF_FOR_MEMBER_FUNCTION_NAME);
|
||||
callableRefForExtensionFunctionName = kotlinScope.declareName(CALLABLE_REF_FOR_EXTENSION_FUNCTION_NAME);
|
||||
boundCallableRefForExtensionFunctionName = kotlinScope.declareName(BOUND_CALLABLE_REF_FOR_EXTENSION_FUNCTION_NAME);
|
||||
callableRefForLocalExtensionFunctionName = kotlinScope.declareName(CALLABLE_REF_FOR_LOCAL_EXTENSION_FUNCTION_NAME);
|
||||
boundCallableRefForLocalExtensionFunctionName = kotlinScope.declareName(BOUND_CALLABLE_REF_FOR_LOCAL_EXTENSION_FUNCTION_NAME);
|
||||
callableRefForConstructorName = kotlinScope.declareName(CALLABLE_REF_FOR_CONSTRUCTOR_NAME);
|
||||
callableRefForTopLevelProperty = kotlinScope.declareName(CALLABLE_REF_FOR_TOP_LEVEL_PROPERTY);
|
||||
callableRefForMemberProperty = kotlinScope.declareName(CALLABLE_REF_FOR_MEMBER_PROPERTY);
|
||||
@@ -287,16 +281,6 @@ public final class Namer {
|
||||
return kotlin(boundCallableRefForExtensionFunctionName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression callableRefForLocalExtensionFunctionReference() {
|
||||
return kotlin(callableRefForLocalExtensionFunctionName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression boundCallableRefForLocalExtensionFunctionReference() {
|
||||
return kotlin(boundCallableRefForLocalExtensionFunctionName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression callableRefForConstructorReference() {
|
||||
return kotlin(callableRefForConstructorName);
|
||||
|
||||
+1
-2
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.js.translate.expression
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsExpression
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsFunction
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsParameter
|
||||
@@ -77,7 +76,7 @@ private fun FunctionDescriptor.getCorrectTypeParameters() =
|
||||
|
||||
|
||||
private val FunctionDescriptor.requiresExtensionReceiverParameter
|
||||
get() = DescriptorUtils.isExtension(this) && visibility != Visibilities.LOCAL
|
||||
get() = DescriptorUtils.isExtension(this)
|
||||
|
||||
fun TranslationContext.translateFunction(declaration: KtDeclarationWithBody, function: JsFunction) {
|
||||
val descriptor = BindingUtils.getFunctionDescriptor(bindingContext(), declaration)
|
||||
|
||||
+1
-9
@@ -223,15 +223,7 @@ object CallableReferenceTranslator {
|
||||
receiver: JsExpression?
|
||||
): JsExpression {
|
||||
val jsFunctionRef = ReferenceTranslator.translateAsValueReference(descriptor, context)
|
||||
if (descriptor.visibility == Visibilities.LOCAL) {
|
||||
if (receiver == null) {
|
||||
return JsInvocation(context.namer().callableRefForLocalExtensionFunctionReference(), jsFunctionRef)
|
||||
}
|
||||
else {
|
||||
return JsInvocation(context.namer().boundCallableRefForLocalExtensionFunctionReference(), receiver, jsFunctionRef)
|
||||
}
|
||||
}
|
||||
else if (AnnotationsUtils.isNativeObject(descriptor)) {
|
||||
if (AnnotationsUtils.isNativeObject(descriptor)) {
|
||||
return translateForMemberFunction(descriptor, context, receiver)
|
||||
}
|
||||
else {
|
||||
|
||||
+3
-3
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.translate.reference;
|
||||
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsExpression;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsNameRef;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsExpression;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsNameRef;
|
||||
import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
|
||||
@@ -18,11 +18,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.translate.utils
|
||||
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.descriptor
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.inlineStrategy
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.psiElement
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.js.backend.ast.*
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.*
|
||||
import org.jetbrains.kotlin.js.inline.util.isCallInvocation
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
import org.jetbrains.kotlin.js.translate.reference.CallExpressionTranslator
|
||||
|
||||
@@ -3,5 +3,5 @@ function A(v) {
|
||||
}
|
||||
|
||||
function nativeBox(b) {
|
||||
return b.bar_asnz92$(new A("foo"), function(i, s) { return "" + this.v + s + i })
|
||||
return b.bar_asnz92$(new A("foo"), function($reciever, i, s) { return "" + $reciever.v + s + i })
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ function A(v) {
|
||||
}
|
||||
|
||||
function bar(a, extLambda) {
|
||||
return extLambda.call(a, 4, "boo")
|
||||
return extLambda(a, 4, "boo")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
function bar(a, extLambda) {
|
||||
return extLambda.call(a, 4, "boo")
|
||||
return extLambda(a, 4, "boo")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user