diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInlinerUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInlinerUtil.kt index a00a975ddbc..c73fc200797 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInlinerUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInlinerUtil.kt @@ -57,7 +57,7 @@ fun MethodInliner.getLambdaIfExistsAndMarkInstructions( else if (processSwap && insnNode.opcode == Opcodes.SWAP) { val swapFrame = frames[insnList.indexOf(insnNode)] ?: return null val dispatchReceiver = swapFrame.top()!!.singleOrNullInsn() - getLambdaIfExistsAndMarkInstructions(dispatchReceiver, false, insnList, frames, toDelete).let { + getLambdaIfExistsAndMarkInstructions(dispatchReceiver, false, insnList, frames, toDelete)?.let { //remove swap instruction (dispatch receiver would be deleted on recursion call): see 'complexStack/simpleExtension.1.kt' test toDelete.add(insnNode) return it diff --git a/compiler/testData/codegen/boxInline/complex/swapAndWith.kt b/compiler/testData/codegen/boxInline/complex/swapAndWith.kt new file mode 100644 index 00000000000..2f60307c2c6 --- /dev/null +++ b/compiler/testData/codegen/boxInline/complex/swapAndWith.kt @@ -0,0 +1,19 @@ +// FILE: 1.kt +package test + +public inline fun with2(receiver: T, body: T.() -> String) = receiver.body() + +// FILE: 2.kt +import test.* + +fun test(item: T?, defaultLink: T.() -> String): String { + return with2("") { + item?.defaultLink() ?: "fail" + } +} + +fun box(): String { + return test("O") { + this + "K" + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/complex/swapAndWith2.kt b/compiler/testData/codegen/boxInline/complex/swapAndWith2.kt new file mode 100644 index 00000000000..bd914e909a6 --- /dev/null +++ b/compiler/testData/codegen/boxInline/complex/swapAndWith2.kt @@ -0,0 +1,19 @@ +// FILE: 1.kt +package test + +public inline fun with2(receiver: T, body: T.() -> String) = receiver.body() + +// FILE: 2.kt +import test.* + +inline fun test(item: T?, defaultLink: T.() -> String): String { + return with2("") { + item?.defaultLink() ?: "fail" + } +} + +fun box(): String { + return test("O") { + this + "K" + } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 3566c2fc1d4..14c71da839c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -619,6 +619,18 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo doTest(fileName); } + @TestMetadata("swapAndWith.kt") + public void testSwapAndWith() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/complex/swapAndWith.kt"); + doTest(fileName); + } + + @TestMetadata("swapAndWith2.kt") + public void testSwapAndWith2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/complex/swapAndWith2.kt"); + doTest(fileName); + } + @TestMetadata("use.kt") public void testUse() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/complex/use.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 9089e877f16..9084c2dd852 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -619,6 +619,18 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doTest(fileName); } + @TestMetadata("swapAndWith.kt") + public void testSwapAndWith() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/complex/swapAndWith.kt"); + doTest(fileName); + } + + @TestMetadata("swapAndWith2.kt") + public void testSwapAndWith2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/complex/swapAndWith2.kt"); + doTest(fileName); + } + @TestMetadata("use.kt") public void testUse() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/complex/use.kt");