From 9b9abb2e10103490da82665501ade5950ad952bc Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Tue, 26 Jul 2016 11:12:17 +0300 Subject: [PATCH] Fix for KT-13182: Regression: compiler internal error at inline #KT-13182 Fixed --- .../kotlin/codegen/inline/MethodInliner.java | 5 ++-- .../boxInline/anonymousObject/kt13182.kt | 25 +++++++++++++++++++ .../BlackBoxInlineCodegenTestGenerated.java | 6 +++++ ...otlinAgainstInlineKotlinTestGenerated.java | 6 +++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/codegen/boxInline/anonymousObject/kt13182.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java index 5b7f4107505..d7e4720e3c3 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java @@ -262,7 +262,8 @@ public class MethodInliner { owner + "." + name + ", info " + transformationInfo; InliningContext parent = inliningContext.getParent(); boolean shouldRegenerate = transformationInfo.shouldRegenerate(isSameModule); - if (shouldRegenerate || (parent != null && parent.isContinuation())) { + boolean isContinuation = parent != null && parent.isContinuation(); + if (shouldRegenerate || isContinuation) { assert shouldRegenerate || inlineCallSiteInfo.getOwnerClassName().equals(transformationInfo.getOldClassName()) : "Only coroutines can call their own constructors"; @@ -270,7 +271,7 @@ public class MethodInliner { AnonymousObjectTransformationInfo info = (AnonymousObjectTransformationInfo) transformationInfo; AnonymousObjectTransformationInfo oldInfo = inliningContext.findAnonymousObjectTransformationInfo(owner); - if (oldInfo != null) { + if (oldInfo != null && isContinuation) { info = oldInfo; } diff --git a/compiler/testData/codegen/boxInline/anonymousObject/kt13182.kt b/compiler/testData/codegen/boxInline/anonymousObject/kt13182.kt new file mode 100644 index 00000000000..91d42494a12 --- /dev/null +++ b/compiler/testData/codegen/boxInline/anonymousObject/kt13182.kt @@ -0,0 +1,25 @@ +// FILE: 1.kt + +package test + +inline fun test(cond: Boolean, crossinline cif: () -> String): String { + return if (cond) { + { cif() }() + } + else { + cif() + } +} +// FILE: 2.kt + +import test.* + +fun box(): String { + val s = "OK" + return test(true) { + { + s + }() + } +} + diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 1a11599e0e4..a61bf411acb 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -127,6 +127,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo doTest(fileName); } + @TestMetadata("kt13182.kt") + public void testKt13182() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt13182.kt"); + doTest(fileName); + } + @TestMetadata("kt6552.kt") public void testKt6552() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index f51e75f3cae..1cf8da5abeb 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -127,6 +127,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doTest(fileName); } + @TestMetadata("kt13182.kt") + public void testKt13182() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt13182.kt"); + doTest(fileName); + } + @TestMetadata("kt6552.kt") public void testKt6552() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");