KT-53957 Fix indy lambdas with extension and context receivers (#5021)
This commit is contained in:
+6
@@ -17432,6 +17432,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/compoundAssignmentOperators.kt");
|
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/compoundAssignmentOperators.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("contextAndExtensionLambdaIndy.kt")
|
||||||
|
public void testContextAndExtensionLambdaIndy() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/contextAndExtensionLambdaIndy.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("contextAndExtensionSameName.kt")
|
@TestMetadata("contextAndExtensionSameName.kt")
|
||||||
public void testContextAndExtensionSameName() throws Exception {
|
public void testContextAndExtensionSameName() throws Exception {
|
||||||
|
|||||||
+7
-1
@@ -446,13 +446,19 @@ internal class LambdaMetafactoryArgumentsBuilder(
|
|||||||
val oldToNew = HashMap<IrValueParameter, IrValueParameter>()
|
val oldToNew = HashMap<IrValueParameter, IrValueParameter>()
|
||||||
var newParameterIndex = 0
|
var newParameterIndex = 0
|
||||||
|
|
||||||
|
lambda.valueParameters.take(lambda.contextReceiverParametersCount).mapTo(newValueParameters) { oldParameter ->
|
||||||
|
oldParameter.copy(lambda, newParameterIndex++).also {
|
||||||
|
oldToNew[oldParameter] = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
newValueParameters.add(
|
newValueParameters.add(
|
||||||
oldExtensionReceiver.copy(lambda, newParameterIndex++, oldExtensionReceiver.name).also {
|
oldExtensionReceiver.copy(lambda, newParameterIndex++, oldExtensionReceiver.name).also {
|
||||||
oldToNew[oldExtensionReceiver] = it
|
oldToNew[oldExtensionReceiver] = it
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
lambda.valueParameters.mapTo(newValueParameters) { oldParameter ->
|
lambda.valueParameters.drop(lambda.contextReceiverParametersCount).mapTo(newValueParameters) { oldParameter ->
|
||||||
oldParameter.copy(lambda, newParameterIndex++).also {
|
oldParameter.copy(lambda, newParameterIndex++).also {
|
||||||
oldToNew[oldParameter] = it
|
oldToNew[oldParameter] = it
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+24
@@ -0,0 +1,24 @@
|
|||||||
|
// !LANGUAGE: +ContextReceivers
|
||||||
|
// TARGET_BACKEND: JVM_IR
|
||||||
|
// JVM_TARGET: 1.8
|
||||||
|
// LAMBDAS: INDY
|
||||||
|
|
||||||
|
class Ctx {
|
||||||
|
val k = "__K__"
|
||||||
|
}
|
||||||
|
|
||||||
|
class Scope {
|
||||||
|
val o = "O"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun accept(block: context(Ctx) Scope.(Int) -> String) = 1
|
||||||
|
fun accept(ref: Any) = 1
|
||||||
|
|
||||||
|
val foo: context(Ctx) Scope.(fooParam: Int) -> String = { fooArg -> o + k[fooArg] }
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
accept(foo)
|
||||||
|
accept(::foo)
|
||||||
|
|
||||||
|
return foo(Ctx(), Scope(), 2)
|
||||||
|
}
|
||||||
+6
@@ -17432,6 +17432,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/compoundAssignmentOperators.kt");
|
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/compoundAssignmentOperators.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("contextAndExtensionLambdaIndy.kt")
|
||||||
|
public void testContextAndExtensionLambdaIndy() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/contextAndExtensionLambdaIndy.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("contextAndExtensionSameName.kt")
|
@TestMetadata("contextAndExtensionSameName.kt")
|
||||||
public void testContextAndExtensionSameName() throws Exception {
|
public void testContextAndExtensionSameName() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user