[FIR2IR] Fix codegen for lambda with dynamic receiver
#KT-57835 Fixed
This commit is contained in:
committed by
Space Team
parent
1c96a87dca
commit
aab1959cc4
+8
-4
@@ -483,20 +483,20 @@ class CallAndReferenceGenerator(
|
||||
|
||||
private fun convertToIrSetCallForDynamic(
|
||||
variableAssignment: FirVariableAssignment,
|
||||
explicitReceiverExpression: IrExpression,
|
||||
receiverExpression: IrExpression,
|
||||
type: IrType,
|
||||
calleeReference: FirReference,
|
||||
symbol: FirBasedSymbol<*>,
|
||||
assignedValue: IrExpression,
|
||||
): IrExpression {
|
||||
var convertedExplicitReceiver = explicitReceiverExpression
|
||||
var convertedExplicitReceiver = receiverExpression
|
||||
|
||||
return variableAssignment.convertWithOffsets { startOffset, endOffset ->
|
||||
when (symbol) {
|
||||
is FirPropertySymbol -> {
|
||||
val name = calleeReference.resolved?.name ?: error("There must be a name")
|
||||
convertedExplicitReceiver = IrDynamicMemberExpressionImpl(
|
||||
startOffset, endOffset, type, name.identifier, explicitReceiverExpression
|
||||
startOffset, endOffset, type, name.identifier, receiverExpression
|
||||
)
|
||||
IrDynamicOperatorExpressionImpl(startOffset, endOffset, type, IrDynamicOperator.EQ).apply {
|
||||
arguments.add(assignedValue)
|
||||
@@ -520,9 +520,13 @@ class CallAndReferenceGenerator(
|
||||
val isDynamicAccess = firSymbol?.origin == FirDeclarationOrigin.DynamicScope
|
||||
|
||||
if (isDynamicAccess) {
|
||||
val receiverExpression = (explicitReceiverExpression
|
||||
?: (variableAssignment.dispatchReceiver as? FirThisReceiverExpression)?.let(visitor::convertToIrExpression)
|
||||
?: error("Must've had a receiver"))
|
||||
|
||||
return convertToIrSetCallForDynamic(
|
||||
variableAssignment,
|
||||
explicitReceiverExpression ?: error("Must've had a receiver"),
|
||||
receiverExpression,
|
||||
type,
|
||||
calleeReference,
|
||||
firSymbol ?: error("Must've had a symbol"),
|
||||
|
||||
+10
@@ -29772,6 +29772,16 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+10
@@ -29772,6 +29772,16 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// TARGET_BACKEND: JS
|
||||
|
||||
fun jso(
|
||||
block: dynamic.() -> Unit,
|
||||
): dynamic {
|
||||
val o = js("{}")
|
||||
block(o)
|
||||
return o
|
||||
}
|
||||
|
||||
fun box() = jso {
|
||||
bar = "OK"
|
||||
}.bar
|
||||
+10
@@ -28356,6 +28356,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+10
@@ -29772,6 +29772,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+10
@@ -29772,6 +29772,16 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+13
@@ -23991,6 +23991,19 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Js extends AbstractLightAnalysisModeTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+16
@@ -21626,6 +21626,22 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaWithDynamicReceiver.kt")
|
||||
public void testLambdaWithDynamicReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/js/lambdaWithDynamicReceiver.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+16
@@ -21764,6 +21764,22 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaWithDynamicReceiver.kt")
|
||||
public void testLambdaWithDynamicReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/js/lambdaWithDynamicReceiver.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+16
@@ -21764,6 +21764,22 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaWithDynamicReceiver.kt")
|
||||
public void testLambdaWithDynamicReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/js/lambdaWithDynamicReceiver.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+16
@@ -21764,6 +21764,22 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lambdaWithDynamicReceiver.kt")
|
||||
public void testLambdaWithDynamicReceiver() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/js/lambdaWithDynamicReceiver.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+14
@@ -24998,6 +24998,20 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@Tag("codegenK2")
|
||||
@Tag("firCodegen")
|
||||
@UseExtTestCaseGroupProvider()
|
||||
@FirPipeline()
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+16
@@ -25508,6 +25508,22 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@Tag("codegenK2")
|
||||
@Tag("firCodegen")
|
||||
@UseExtTestCaseGroupProvider()
|
||||
@FirPipeline()
|
||||
@UsePartialLinkage(mode = Mode.DISABLED)
|
||||
@Tag("no-partial-linkage-may-be-skipped")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+13
@@ -24743,6 +24743,19 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@Tag("codegen")
|
||||
@Tag("k1Codegen")
|
||||
@UseExtTestCaseGroupProvider()
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+15
@@ -25253,6 +25253,21 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@Tag("codegen")
|
||||
@Tag("k1Codegen")
|
||||
@UseExtTestCaseGroupProvider()
|
||||
@UsePartialLinkage(mode = Mode.DISABLED)
|
||||
@Tag("no-partial-linkage-may-be-skipped")
|
||||
public class Js {
|
||||
@Test
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
Generated
+13
@@ -19244,6 +19244,19 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/js")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Js extends AbstractIrCodegenBoxWasmTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInJs() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/js"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/jvm8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user