KT-52459 Handle context receivers when generating a bridge

This commit is contained in:
Pavel Mikhailovskii
2022-12-27 16:19:59 +00:00
committed by Space Team
parent d735fa6567
commit 3704d54101
4 changed files with 36 additions and 0 deletions
@@ -17540,6 +17540,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52373.kt");
}
@Test
@TestMetadata("kt52459.kt")
public void testKt52459() throws Exception {
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52459.kt");
}
@Test
@TestMetadata("kt53846.kt")
public void testKt53846() throws Exception {
@@ -591,6 +591,7 @@ internal class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass
} else {
from.valueParameters.map { it.copyWithTypeErasure(this, visibleTypeParameters) }
}
contextReceiverParametersCount = from.contextReceiverParametersCount
}
private fun IrValueParameter.copyWithTypeErasure(
@@ -0,0 +1,23 @@
// !LANGUAGE: +ContextReceivers
// TARGET_BACKEND: JVM_IR
interface I<T>{
context(A)
fun T.foo(): String
}
class A(val a: String)
class B(val b: String)
object O: I<B>{
context(A)
override fun B.foo(): String = this@A.a + this@B.b
}
fun box(): String {
with(A("O")){
with(O as I<B>){
return B("K").foo()
}
}
}
@@ -17540,6 +17540,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52373.kt");
}
@Test
@TestMetadata("kt52459.kt")
public void testKt52459() throws Exception {
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52459.kt");
}
@Test
@TestMetadata("kt53846.kt")
public void testKt53846() throws Exception {