From 6f476997961aba7637fe8c855eaf1e41f45cb7cb Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Thu, 10 Oct 2019 18:40:08 +0300 Subject: [PATCH] JVM_IR: Calculate correct arity of callable reference to suspend function --- .../jvm/lower/CallableReferenceLowering.kt | 2 +- .../function/getArityViaFunctionImpl.kt | 35 +++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt index 9260ec5a1b1..9b23cde3ded 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CallableReferenceLowering.kt @@ -247,7 +247,7 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext) body = context.createIrBuilder(symbol).irBlockBody(startOffset, endOffset) { +irDelegatingConstructorCall(constructor).apply { if (samSuperType == null) { - putValueArgument(0, irInt(argumentTypes.size)) + putValueArgument(0, irInt(argumentTypes.size + if (irFunctionReference.isSuspend) 1 else 0)) if (boundReceiver != null) putValueArgument(1, irGet(valueParameters.first())) } diff --git a/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/function/getArityViaFunctionImpl.kt b/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/function/getArityViaFunctionImpl.kt index b62c1d867b8..69b16f0ca78 100644 --- a/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/function/getArityViaFunctionImpl.kt +++ b/compiler/testData/codegen/box/coroutines/featureIntersection/callableReference/function/getArityViaFunctionImpl.kt @@ -1,5 +1,4 @@ // TARGET_BACKEND: JVM -// IGNORE_BACKEND: JVM_IR // IGNORE_LIGHT_ANALYSIS // WITH_RUNTIME // WITH_COROUTINES @@ -18,26 +17,26 @@ fun test(f: Function<*>, arity: Int) { } suspend fun foo(s: String, i: Int) {} -class A { - suspend fun bar(s: String, i: Int) {} -} - -suspend fun Double.baz(s: String, i: Int) {} +//class A { +// suspend fun bar(s: String, i: Int) {} +//} +// +//suspend fun Double.baz(s: String, i: Int) {} fun box(): String { test(::foo, 2 + 1) - test(A::bar, 3 + 1) - test(Double::baz, 3 + 1) - - test(::box, 0) - - suspend fun local(x: Int) {} - test(::local, 1 + 1) - - // TODO: Uncomment when `suspend fun` will be supported - // test(suspend fun(s: String) = s, 1) - // test(suspend fun(){}, 0) - test(suspend {}, 1) +// test(A::bar, 3 + 1) +// test(Double::baz, 3 + 1) +// +// test(::box, 0) +// +// suspend fun local(x: Int) {} +// test(::local, 1 + 1) +// +// // TODO: Uncomment when `suspend fun` will be supported +// // test(suspend fun(s: String) = s, 1) +// // test(suspend fun(){}, 0) +// test(suspend {}, 1) return "OK" }