From 1e3f84402d68e7ef41d6eb84e45dbd244ceed875 Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Fri, 8 Apr 2022 23:31:49 +0200 Subject: [PATCH] Safely check for suspend function parent The issue here is that the function can be in unlowered file, and thus its parent package fragment and not class. #KT-49317 Fixed --- .../FirBlackBoxCodegenTestGenerated.java | 6 +++++ .../backend/jvm/ir/JvmIrCoroutineUtils.kt | 4 +-- .../codegen/box/coroutines/kt49317.kt | 26 +++++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 +++++ .../IrBlackBoxCodegenTestGenerated.java | 6 +++++ .../LightAnalysisModeTestGenerated.java | 5 ++++ .../js/test/JsCodegenBoxTestGenerated.java | 6 +++++ .../test/ir/IrJsCodegenBoxTestGenerated.java | 6 +++++ .../IrCodegenBoxWasmTestGenerated.java | 5 ++++ .../NativeCodegenBoxTestGenerated.java | 6 +++++ 10 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/codegen/box/coroutines/kt49317.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index cf5e1191e1e..dc40f00a8c2 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -10179,6 +10179,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); } + @Test + @TestMetadata("kt49317.kt") + public void testKt49317() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49317.kt"); + } + @Test @TestMetadata("kt49645.kt") public void testKt49645() throws Exception { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrCoroutineUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrCoroutineUtils.kt index 8b67bb97398..fd2412c7b3b 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrCoroutineUtils.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/JvmIrCoroutineUtils.kt @@ -38,9 +38,9 @@ private fun IrFunction.isInvokeOfSuspendCallableReference(): Boolean = && parentAsClass.origin == JvmLoweredDeclarationOrigin.FUNCTION_REFERENCE_IMPL private fun IrFunction.isBridgeToSuspendImplMethod(): Boolean = - isSuspend && this is IrSimpleFunction && parentAsClass.functions.any { + isSuspend && this is IrSimpleFunction && (parent as? IrClass)?.functions?.any { it.name.asString() == name.asString() + SUSPEND_IMPL_NAME_SUFFIX && it.attributeOwnerId == attributeOwnerId - } + } == true private fun IrFunction.isStaticInlineClassReplacementDelegatingCall(): Boolean { if (this !is IrAttributeContainer || isStaticInlineClassReplacement) return false diff --git a/compiler/testData/codegen/box/coroutines/kt49317.kt b/compiler/testData/codegen/box/coroutines/kt49317.kt new file mode 100644 index 00000000000..8463196fad5 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/kt49317.kt @@ -0,0 +1,26 @@ +// WITH_STDLIB + +// FILE: 2.kt +package other +import builders.* +import kotlin.coroutines.* + +fun test() { + suspend { + foo { } + }.startCoroutine(Continuation(EmptyCoroutineContext) { + it.getOrThrow() + }) +} + +fun box(): String { + test() + return "OK" +} + +// FILE: 1.kt +package builders + +suspend fun foo( + a: suspend () -> Unit = {} +) {} \ No newline at end of file diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 2fc0616fea7..339304d41be 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -10053,6 +10053,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); } + @Test + @TestMetadata("kt49317.kt") + public void testKt49317() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49317.kt"); + } + @Test @TestMetadata("kt49645.kt") public void testKt49645() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index ab90ba6567c..99b38f8a34a 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -10179,6 +10179,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); } + @Test + @TestMetadata("kt49317.kt") + public void testKt49317() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49317.kt"); + } + @Test @TestMetadata("kt49645.kt") public void testKt49645() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 780905be286..e3dce2b162f 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -7914,6 +7914,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/coroutines/kt46813.kt"); } + @TestMetadata("kt49317.kt") + public void testKt49317() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49317.kt"); + } + @TestMetadata("kt49645.kt") public void testKt49645() throws Exception { runTest("compiler/testData/codegen/box/coroutines/kt49645.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index 35befa3a343..34430f46825 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -7157,6 +7157,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); } + @Test + @TestMetadata("kt49317.kt") + public void testKt49317() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49317.kt"); + } + @Test @TestMetadata("kt51530.kt") public void testKt51530() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index 52efc1044b4..9ca64771247 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -7199,6 +7199,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); } + @Test + @TestMetadata("kt49317.kt") + public void testKt49317() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49317.kt"); + } + @Test @TestMetadata("kt51530.kt") public void testKt51530() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index c5fb8d5d1a2..4f6537f41fa 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -6241,6 +6241,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); } + @TestMetadata("kt49317.kt") + public void testKt49317() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49317.kt"); + } + @TestMetadata("kt51530.kt") public void testKt51530() throws Exception { runTest("compiler/testData/codegen/box/coroutines/kt51530.kt"); diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index ba6d7e16df3..396e217b4ac 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -8041,6 +8041,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest runTest("compiler/testData/codegen/box/coroutines/kt49168.kt"); } + @Test + @TestMetadata("kt49317.kt") + public void testKt49317() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/kt49317.kt"); + } + @Test @TestMetadata("kt51530.kt") public void testKt51530() throws Exception {