KT-13025: when receiver of call of 'invoke' method is a Function, check whether receiver is an extension function and generate additional '.call' invocation. Fix #KT-13025

This commit is contained in:
Alexey Andreev
2016-07-12 16:34:09 +03:00
parent c767b3d0ac
commit df86840515
3 changed files with 29 additions and 1 deletions
@@ -61,4 +61,8 @@ public final class InvokeConventionTest extends AbstractExpressionTest {
public void testInvokeWithImplicitDispatchReceiverAndExtensionReceiver() throws Exception {
checkFooBoxIsOk();
}
public void testExtensionInvoke() throws Exception {
checkFooBoxIsOk();
}
}
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.js.translate.callTranslator
import com.google.dart.compiler.backend.js.ast.*
import org.jetbrains.kotlin.builtins.functions.FunctionInvokeDescriptor
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.descriptors.Visibilities
@@ -179,7 +180,14 @@ object InvokeIntrinsic : FunctionCallCase() {
}
override fun FunctionCallInfo.dispatchReceiver(): JsExpression {
return JsInvocation(dispatchReceiver!!, argumentsInfo.translateArguments)
val receiver = resolvedCall.dispatchReceiver!!
val jsReceiver = if (receiver.type.isExtensionFunctionType) {
pureFqn(Namer.CALL_FUNCTION, dispatchReceiver)
}
else {
dispatchReceiver!!
}
return JsInvocation(jsReceiver, argumentsInfo.translateArguments)
}
/**
@@ -0,0 +1,16 @@
package foo
class A(val f: (B.() -> Int)?)
class B(val x: Int)
fun test(g: (B.() -> Int)?): Int? {
val a = A(g)
val b = B(2)
return a.f?.invoke(b)
}
fun box(): String {
assertEquals(5, test { x + 3 })
return "OK"
}