From 3dc4f8a2ffa106da7d2c2bca508c270b3dd0f635 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Wed, 28 Jun 2017 10:24:13 +0300 Subject: [PATCH] Do not write generics for $suspendImpl synthetic method #KT-18252 Fixed --- .../kotlin/codegen/FunctionCodegen.java | 7 +++ .../openFunWithJava.kt | 60 +++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 6 ++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++ .../LightAnalysisModeTestGenerated.java | 6 ++ 5 files changed, 85 insertions(+) create mode 100644 compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/openFunWithJava.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index 870b79101e2..b75d810296c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -229,6 +229,13 @@ public class FunctionCodegen { } asmMethod = CoroutineCodegenUtilKt.getImplForOpenMethod(asmMethod, v.getThisName()); + // remove generic signature as it's unnecessary for synthetic methods + jvmSignature = + new JvmMethodGenericSignature( + asmMethod, + jvmSignature.getValueParameters(), + null + ); mv.visitMethodInsn( Opcodes.INVOKESTATIC, diff --git a/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/openFunWithJava.kt b/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/openFunWithJava.kt new file mode 100644 index 00000000000..0d22667d747 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/openFunWithJava.kt @@ -0,0 +1,60 @@ +// WITH_RUNTIME +// WITH_COROUTINES +// FILE: main.kt +// TARGET_BACKEND: JVM +import helpers.* +import kotlin.coroutines.experimental.* +import kotlin.coroutines.experimental.intrinsics.* + + + +open class A(val v: String) { + suspend fun suspendThere(v: String): String = suspendCoroutineOrReturn { x -> + x.resume(v) + COROUTINE_SUSPENDED + } + + open suspend fun suspendHere(): String = suspendThere("O") + suspendThere(v) +} + +class B(v: String) : A(v) { + override suspend fun suspendHere(): String = super.suspendHere() + suspendThere("56") +} + +fun builder(c: suspend A.() -> Unit) { + c.startCoroutine(B("K"), EmptyContinuation) +} + +fun box(): String { + var result = JavaClass.foo() + + if (result != "OK56") return "fail 1: $result" + + return "OK" +} + +// FILE: JavaClass.java +import kotlin.coroutines.experimental.*; +public class JavaClass { + public static String foo() { + final String[] res = new String[1]; + + new B("K").suspendHere(new Continuation() { + @Override + public CoroutineContext getContext() { + return EmptyCoroutineContext.INSTANCE; + } + + @Override + public void resume(String s) { + res[0] = s; + } + + @Override + public void resumeWithException(Throwable throwable) { + } + }); + + return res[0]; + } +} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 827d670641c..b9a6cb48568 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -5704,6 +5704,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("openFunWithJava.kt") + public void testOpenFunWithJava() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/openFunWithJava.kt"); + doTest(fileName); + } + @TestMetadata("operators.kt") public void testOperators() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/operators.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index f589f03c130..b8b646bf2e1 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -5704,6 +5704,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("openFunWithJava.kt") + public void testOpenFunWithJava() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/openFunWithJava.kt"); + doTest(fileName); + } + @TestMetadata("operators.kt") public void testOperators() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/operators.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index aee39ba859f..199c1b12213 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -5704,6 +5704,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("openFunWithJava.kt") + public void testOpenFunWithJava() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/openFunWithJava.kt"); + doTest(fileName); + } + @TestMetadata("operators.kt") public void testOperators() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/operators.kt");