From 7ded115dddb04370766d90874db7b3cddb83d2a7 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Fri, 11 May 2018 13:44:42 +0300 Subject: [PATCH] Fixed bug in Inliner + test --- .../konan/lower/DeepCopyIrTreeWithDescriptors.kt | 5 +++-- backend.native/tests/build.gradle | 5 +++++ .../codegen/inline/returnLocalClassFromBlock.kt | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 backend.native/tests/codegen/inline/returnLocalClassFromBlock.kt diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DeepCopyIrTreeWithDescriptors.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DeepCopyIrTreeWithDescriptors.kt index 01821075111..bc2cc9b11ea 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DeepCopyIrTreeWithDescriptors.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/DeepCopyIrTreeWithDescriptors.kt @@ -35,6 +35,7 @@ import org.jetbrains.kotlin.ir.symbols.impl.createValueSymbol import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid +import org.jetbrains.kotlin.ir.visitors.acceptVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.DescriptorUtils @@ -60,9 +61,9 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr fun copy(irElement: IrElement, typeSubstitutor: TypeSubstitutor?): IrElement { this.typeSubstitutor = typeSubstitutor // Create all class descriptors and all necessary descriptors in order to create KotlinTypes. - irElement.acceptChildrenVoid(DescriptorCollectorCreatePhase()) + irElement.acceptVoid(DescriptorCollectorCreatePhase()) // Initialize all created descriptors possibly using previously created types. - irElement.acceptChildrenVoid(DescriptorCollectorInitPhase()) + irElement.acceptVoid(DescriptorCollectorInitPhase()) return irElement.accept(InlineCopyIr(), null) } diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index d0b0c748d21..47dcf0dc370 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -2326,6 +2326,11 @@ task inline_statementAsLastExprInBlock(type: RunKonanTest) { source = "codegen/inline/statementAsLastExprInBlock.kt" } +task inline_returnLocalClassFromBlock(type: RunKonanTest) { + goldValue = "Zzz\n" + source = "codegen/inline/returnLocalClassFromBlock.kt" +} + task deserialized_inline0(type: RunKonanTest) { source = "serialization/deserialized_inline0.kt" } diff --git a/backend.native/tests/codegen/inline/returnLocalClassFromBlock.kt b/backend.native/tests/codegen/inline/returnLocalClassFromBlock.kt new file mode 100644 index 00000000000..c4dc9da895d --- /dev/null +++ b/backend.native/tests/codegen/inline/returnLocalClassFromBlock.kt @@ -0,0 +1,15 @@ +package codegen.inline.returnLocalClassFromBlock + +import kotlin.test.* + +inline fun call(block: ()->R): R { + try { + return block() + } finally { + println("Zzz") + } +} + +@Test fun runTest() { + call { class Z(); Z() } +}