KT-53551 KT-52213 KT-58476 Fix handling of suspend functional types with context receivers
This commit is contained in:
committed by
Space Team
parent
c2ee9bb1a4
commit
88453a05f1
+18
@@ -18178,6 +18178,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52207.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52213.kt")
|
||||
public void testKt52213() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52213.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52373.kt")
|
||||
public void testKt52373() throws Exception {
|
||||
@@ -18190,6 +18196,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52459.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt53551.kt")
|
||||
public void testKt53551() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt53551.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt53846.kt")
|
||||
public void testKt53846() throws Exception {
|
||||
@@ -18208,6 +18220,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt56508.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt58476.kt")
|
||||
public void testKt58476() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt58476.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overload.kt")
|
||||
public void testOverload() throws Exception {
|
||||
|
||||
+18
@@ -18178,6 +18178,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52207.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52213.kt")
|
||||
public void testKt52213() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52213.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52373.kt")
|
||||
public void testKt52373() throws Exception {
|
||||
@@ -18190,6 +18196,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52459.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt53551.kt")
|
||||
public void testKt53551() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt53551.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt53846.kt")
|
||||
public void testKt53846() throws Exception {
|
||||
@@ -18208,6 +18220,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt56508.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt58476.kt")
|
||||
public void testKt58476() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt58476.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overload.kt")
|
||||
public void testOverload() throws Exception {
|
||||
|
||||
+18
@@ -18178,6 +18178,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52207.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52213.kt")
|
||||
public void testKt52213() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52213.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52373.kt")
|
||||
public void testKt52373() throws Exception {
|
||||
@@ -18190,6 +18196,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52459.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt53551.kt")
|
||||
public void testKt53551() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt53551.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt53846.kt")
|
||||
public void testKt53846() throws Exception {
|
||||
@@ -18208,6 +18220,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt56508.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt58476.kt")
|
||||
public void testKt58476() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt58476.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overload.kt")
|
||||
public void testOverload() throws Exception {
|
||||
|
||||
+4
-1
@@ -247,7 +247,10 @@ private class SuspendLambdaLowering(context: JvmBackendContext) : SuspendLowerin
|
||||
override fun visitGetValue(expression: IrGetValue): IrExpression {
|
||||
val parameter = (expression.symbol.owner as? IrValueParameter)?.takeIf { it.parent == irFunction }
|
||||
?: return expression
|
||||
val lvar = localVals[parameter.index + if (irFunction.extensionReceiverParameter != null) 1 else 0]
|
||||
val varIndex = if (parameter.index < 0) irFunction.contextReceiverParametersCount
|
||||
else if (parameter.index < irFunction.contextReceiverParametersCount || irFunction.extensionReceiverParameter == null) parameter.index
|
||||
else parameter.index + 1
|
||||
val lvar = localVals[varIndex]
|
||||
?: return expression
|
||||
return IrGetValueImpl(expression.startOffset, expression.endOffset, lvar.symbol)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// !LANGUAGE: +ContextReceivers
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
interface Context
|
||||
|
||||
class Receiver
|
||||
|
||||
interface Action {
|
||||
context (Context)
|
||||
fun run()
|
||||
}
|
||||
|
||||
fun execute(block: suspend context(Context) Receiver.(Action) -> Unit) = Unit
|
||||
|
||||
fun box(): String {
|
||||
execute { it.run() }
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// !LANGUAGE: +ContextReceivers
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
import helpers.*
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
|
||||
fun box(): String {
|
||||
withFooBar { fooBarBaz() }
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun <T> runBlocking(c: suspend () -> T): T {
|
||||
var res: T? = null
|
||||
c.startCoroutine(Continuation(EmptyCoroutineContext) {
|
||||
res = it.getOrThrow()
|
||||
})
|
||||
return res!!
|
||||
}
|
||||
|
||||
class Foo
|
||||
class Bar
|
||||
class Baz
|
||||
|
||||
context(Foo, Bar)
|
||||
fun Baz.fooBarBaz() { }
|
||||
|
||||
fun withFooBar(block: suspend context(Foo, Bar) Baz.() -> Unit) {
|
||||
val foo = Foo()
|
||||
val bar = Bar()
|
||||
val baz = Baz()
|
||||
runBlocking { block(foo, bar, baz) }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// !LANGUAGE: +ContextReceivers
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
|
||||
class InContext
|
||||
class MyReciever {
|
||||
public suspend fun MyOutput.innerFun(): Int = 123
|
||||
}
|
||||
class MyOutput
|
||||
|
||||
// 2 - Declare the caller that calls the suspended function in a context
|
||||
public fun caller(block: suspend context(InContext) MyReciever.() -> Int): MyOutput = MyOutput()
|
||||
|
||||
fun box(): String {
|
||||
val out1 = caller { MyOutput().innerFun() }
|
||||
val out2 = with (InContext()) { caller { MyOutput().innerFun() } }
|
||||
val out3 = caller { with (InContext()) { MyOutput().innerFun() } }
|
||||
return "OK"
|
||||
}
|
||||
+18
@@ -18178,6 +18178,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52207.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52213.kt")
|
||||
public void testKt52213() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52213.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52373.kt")
|
||||
public void testKt52373() throws Exception {
|
||||
@@ -18190,6 +18196,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52459.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt53551.kt")
|
||||
public void testKt53551() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt53551.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt53846.kt")
|
||||
public void testKt53846() throws Exception {
|
||||
@@ -18208,6 +18220,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt56508.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt58476.kt")
|
||||
public void testKt58476() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt58476.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overload.kt")
|
||||
public void testOverload() throws Exception {
|
||||
|
||||
+18
@@ -18178,6 +18178,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52207.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52213.kt")
|
||||
public void testKt52213() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52213.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt52373.kt")
|
||||
public void testKt52373() throws Exception {
|
||||
@@ -18190,6 +18196,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52459.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt53551.kt")
|
||||
public void testKt53551() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt53551.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt53846.kt")
|
||||
public void testKt53846() throws Exception {
|
||||
@@ -18208,6 +18220,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt56508.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt58476.kt")
|
||||
public void testKt58476() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt58476.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overload.kt")
|
||||
public void testOverload() throws Exception {
|
||||
|
||||
+15
@@ -15084,6 +15084,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52207.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt52213.kt")
|
||||
public void testKt52213() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52213.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt52373.kt")
|
||||
public void testKt52373() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52373.kt");
|
||||
@@ -15094,6 +15099,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt52459.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt53551.kt")
|
||||
public void testKt53551() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt53551.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt53846.kt")
|
||||
public void testKt53846() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt53846.kt");
|
||||
@@ -15109,6 +15119,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt56508.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt58476.kt")
|
||||
public void testKt58476() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/kt58476.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overload.kt")
|
||||
public void testOverload() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/overload.kt");
|
||||
|
||||
Reference in New Issue
Block a user