Fix codegen for context-receiver contained super class constructor calls
^KT-51889 In Progress
This commit is contained in:
+6
@@ -16752,6 +16752,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/simpleCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("superClassAndSubClassWithContextReceiver.kt")
|
||||
public void testSuperClassAndSubClassWithContextReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/superClassAndSubClassWithContextReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendContextualWithExtension.kt")
|
||||
public void testSuspendContextualWithExtension() throws Exception {
|
||||
|
||||
+6
-7
@@ -34,10 +34,7 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtConstructorDelegationCall
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.ValueArgument
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments
|
||||
import org.jetbrains.kotlin.psi2ir.intermediate.*
|
||||
@@ -264,10 +261,12 @@ fun StatementGenerator.generateCallReceiver(
|
||||
else -> {
|
||||
dispatchReceiverValue = generateReceiverOrNull(ktDefaultElement, dispatchReceiver)
|
||||
extensionReceiverValue = generateReceiverOrNull(ktDefaultElement, extensionReceiver)
|
||||
contextReceiverValues = if (ktDefaultElement is KtConstructorDelegationCall) contextReceivers.mapNotNull {
|
||||
generateContextReceiverForDelegatingConstructorCall(ktDefaultElement, it as ContextClassReceiver)
|
||||
contextReceiverValues = when (ktDefaultElement) {
|
||||
is KtConstructorDelegationCall, is KtSuperTypeCallEntry -> contextReceivers.mapNotNull {
|
||||
generateContextReceiverForDelegatingConstructorCall(ktDefaultElement, it as ContextClassReceiver)
|
||||
}
|
||||
else -> contextReceivers.mapNotNull { generateReceiverOrNull(ktDefaultElement, it) }
|
||||
}
|
||||
else contextReceivers.mapNotNull { generateReceiverOrNull(ktDefaultElement, it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// !LANGUAGE: +ContextReceivers
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
|
||||
class Components(val x: String)
|
||||
|
||||
context(Components)
|
||||
abstract class A {
|
||||
fun foo(): String = x
|
||||
}
|
||||
|
||||
context(Components)
|
||||
class B : A()
|
||||
|
||||
fun box(): String {
|
||||
return with(Components("OK")) {
|
||||
B().foo()
|
||||
}
|
||||
}
|
||||
+6
@@ -16752,6 +16752,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/simpleCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("superClassAndSubClassWithContextReceiver.kt")
|
||||
public void testSuperClassAndSubClassWithContextReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/superClassAndSubClassWithContextReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendContextualWithExtension.kt")
|
||||
public void testSuspendContextualWithExtension() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user