Fix for KT-13040: Invalid bytecode generated for extension lambda invocation with safe call
#KT-13040 Fixed
This commit is contained in:
@@ -57,7 +57,7 @@ fun MethodInliner.getLambdaIfExistsAndMarkInstructions(
|
|||||||
else if (processSwap && insnNode.opcode == Opcodes.SWAP) {
|
else if (processSwap && insnNode.opcode == Opcodes.SWAP) {
|
||||||
val swapFrame = frames[insnList.indexOf(insnNode)] ?: return null
|
val swapFrame = frames[insnList.indexOf(insnNode)] ?: return null
|
||||||
val dispatchReceiver = swapFrame.top()!!.singleOrNullInsn()
|
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
|
//remove swap instruction (dispatch receiver would be deleted on recursion call): see 'complexStack/simpleExtension.1.kt' test
|
||||||
toDelete.add(insnNode)
|
toDelete.add(insnNode)
|
||||||
return it
|
return it
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// FILE: 1.kt
|
||||||
|
package test
|
||||||
|
|
||||||
|
public inline fun <T> with2(receiver: T, body: T.() -> String) = receiver.body()
|
||||||
|
|
||||||
|
// FILE: 2.kt
|
||||||
|
import test.*
|
||||||
|
|
||||||
|
fun <T : Any> test(item: T?, defaultLink: T.() -> String): String {
|
||||||
|
return with2("") {
|
||||||
|
item?.defaultLink() ?: "fail"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return test("O") {
|
||||||
|
this + "K"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// FILE: 1.kt
|
||||||
|
package test
|
||||||
|
|
||||||
|
public inline fun <T> with2(receiver: T, body: T.() -> String) = receiver.body()
|
||||||
|
|
||||||
|
// FILE: 2.kt
|
||||||
|
import test.*
|
||||||
|
|
||||||
|
inline fun <T : Any> test(item: T?, defaultLink: T.() -> String): String {
|
||||||
|
return with2("") {
|
||||||
|
item?.defaultLink() ?: "fail"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return test("O") {
|
||||||
|
this + "K"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -619,6 +619,18 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("use.kt")
|
||||||
public void testUse() throws Exception {
|
public void testUse() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/complex/use.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/complex/use.kt");
|
||||||
|
|||||||
+12
@@ -619,6 +619,18 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("use.kt")
|
||||||
public void testUse() throws Exception {
|
public void testUse() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/complex/use.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/complex/use.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user