From a2612c1eaee9821ea0e650adbaebdf91490af03e Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 7 Nov 2018 18:09:25 +0100 Subject: [PATCH] Fix generic signature for KSuspendFunction types in bytecode #KT-27560 Fixed --- .../codegen/state/KotlinTypeMapper.java | 3 +- .../suspendFunctionReference.kt | 39 +++++++++++++++++++ .../compiler/WriteSignatureTestGenerated.java | 5 +++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/writeSignature/callableReference/suspendFunctionReference.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java index 477bbdcc35b..c110f31747d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/KotlinTypeMapper.java @@ -647,7 +647,8 @@ public class KotlinTypeMapper { if (classDescriptor instanceof FunctionClassDescriptor) { FunctionClassDescriptor functionClass = (FunctionClassDescriptor) classDescriptor; if (functionClass.hasBigArity() || - functionClass.getFunctionKind() == FunctionClassDescriptor.Kind.KFunction) { + functionClass.getFunctionKind() == FunctionClassDescriptor.Kind.KFunction || + functionClass.getFunctionKind() == FunctionClassDescriptor.Kind.KSuspendFunction) { // kotlin.reflect.KFunction{n} is mapped to kotlin.reflect.KFunction (for all n), and // kotlin.Function{n} is mapped to kotlin.jvm.functions.FunctionN (for n > 22). // So for these classes, we need to skip all type arguments except the very last one diff --git a/compiler/testData/writeSignature/callableReference/suspendFunctionReference.kt b/compiler/testData/writeSignature/callableReference/suspendFunctionReference.kt new file mode 100644 index 00000000000..b26db329a12 --- /dev/null +++ b/compiler/testData/writeSignature/callableReference/suspendFunctionReference.kt @@ -0,0 +1,39 @@ +interface I + +abstract class AbstractTest { + abstract fun normal(): suspend (String) -> Unit + + abstract fun extension(): suspend Double.() -> Double + + abstract fun bigArity(): suspend (I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I) -> Unit +} + +class Test : AbstractTest() { + override fun normal() = ::suspendNormal + + override fun extension() = Double::suspendExtension + + override fun bigArity() = this::suspendBigArity + + private suspend fun suspendNormal(s: String) {} + + private suspend fun suspendBigArity( + p01: I, p02: I, p03: I, p04: I, p05: I, p06: I, p07: I, p08: I, p09: I, p10: I, + p11: I, p12: I, p13: I, p14: I, p15: I, p16: I, p17: I, p18: I, p19: I, p20: I, + p21: I, p22: I, p23: I, p24: I, p25: I, p26: I, p27: I, p28: I, p29: I, p30: I + ) {} +} + +private suspend fun Double.suspendExtension(): Double = this + +// method: Test::normal +// jvm signature: ()Lkotlin/reflect/KFunction; +// generic signature: ()Lkotlin/reflect/KFunction; + +// method: Test::extension +// jvm signature: ()Lkotlin/reflect/KFunction; +// generic signature: ()Lkotlin/reflect/KFunction; + +// method: Test::bigArity +// jvm signature: ()Lkotlin/reflect/KFunction; +// generic signature: ()Lkotlin/reflect/KFunction; diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/WriteSignatureTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/WriteSignatureTestGenerated.java index 13fd132b013..3652ecebe35 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/WriteSignatureTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/WriteSignatureTestGenerated.java @@ -198,6 +198,11 @@ public class WriteSignatureTestGenerated extends AbstractWriteSignatureTest { public void testPropertyReferenceGet() throws Exception { runTest("compiler/testData/writeSignature/callableReference/propertyReferenceGet.kt"); } + + @TestMetadata("suspendFunctionReference.kt") + public void testSuspendFunctionReference() throws Exception { + runTest("compiler/testData/writeSignature/callableReference/suspendFunctionReference.kt"); + } } @TestMetadata("compiler/testData/writeSignature/constructor")