From 8a402bcacda0e62e92f30d9ecc77e204ac5cfb4b Mon Sep 17 00:00:00 2001 From: Pavel Mikhailovskii Date: Thu, 30 Jun 2022 13:30:51 +0200 Subject: [PATCH] KT-52875 Fix extension function literal creation with -Xlambdas=indy --- .../runners/codegen/FirBlackBoxCodegenTestGenerated.java | 6 ++++++ .../backend/jvm/lower/indy/LambdaMetafactoryArguments.kt | 2 +- .../testData/codegen/box/invokedynamic/lambdas/kt52875.kt | 6 ++++++ .../test/runners/codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ .../runners/codegen/IrBlackBoxCodegenTestGenerated.java | 6 ++++++ .../kotlin/codegen/LightAnalysisModeTestGenerated.java | 5 +++++ .../jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java | 6 ++++++ .../kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java | 6 ++++++ .../wasm/semantics/IrCodegenBoxWasmTestGenerated.java | 5 +++++ .../konan/blackboxtest/NativeCodegenBoxTestGenerated.java | 6 ++++++ 10 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/invokedynamic/lambdas/kt52875.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 90a2ca49fbb..220141b85d7 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -26240,6 +26240,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/invokedynamic/lambdas/genericLambdaSignature.kt"); } + @Test + @TestMetadata("kt52875.kt") + public void testKt52875() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/lambdas/kt52875.kt"); + } + @Test @TestMetadata("lambdaSerializable.kt") public void testLambdaSerializable() throws Exception { diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt index 89e338d925c..37e1f1f10cd 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt @@ -335,7 +335,7 @@ internal class LambdaMetafactoryArgumentsBuilder( } val newReference = - if (implFun.origin == IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA) + if (implFun.origin == IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA || implFun.isAnonymousFunction) remapExtensionLambda(implFun as IrSimpleFunction, reference) else reference diff --git a/compiler/testData/codegen/box/invokedynamic/lambdas/kt52875.kt b/compiler/testData/codegen/box/invokedynamic/lambdas/kt52875.kt new file mode 100644 index 00000000000..ce584b0df7c --- /dev/null +++ b/compiler/testData/codegen/box/invokedynamic/lambdas/kt52875.kt @@ -0,0 +1,6 @@ +// LAMBDAS: INDY + +fun appendTo(s: String) = + fun Any?.() = s + this + +fun box() = appendTo("O")("K") diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index e4143e7edb5..4677e8f201a 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -25730,6 +25730,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/invokedynamic/lambdas/genericLambdaSignature.kt"); } + @Test + @TestMetadata("kt52875.kt") + public void testKt52875() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/lambdas/kt52875.kt"); + } + @Test @TestMetadata("lambdaSerializable.kt") public void testLambdaSerializable() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index d0597c61337..8d5933d16d6 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -26240,6 +26240,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/invokedynamic/lambdas/genericLambdaSignature.kt"); } + @Test + @TestMetadata("kt52875.kt") + public void testKt52875() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/lambdas/kt52875.kt"); + } + @Test @TestMetadata("lambdaSerializable.kt") public void testLambdaSerializable() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index f4e0e53a427..7618cd3164e 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -21673,6 +21673,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/invokedynamic/lambdas/extensionLambda.kt"); } + @TestMetadata("kt52875.kt") + public void testKt52875() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/lambdas/kt52875.kt"); + } + @TestMetadata("nestedIndyLambdas.kt") public void testNestedIndyLambdas() throws Exception { runTest("compiler/testData/codegen/box/invokedynamic/lambdas/nestedIndyLambdas.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index 482d48c3bfd..e3d6ae91b18 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -20656,6 +20656,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/invokedynamic/lambdas"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); } + @Test + @TestMetadata("kt52875.kt") + public void testKt52875() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/lambdas/kt52875.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/invokedynamic/lambdas/inlineClassInSignature") @TestDataPath("$PROJECT_ROOT") diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index 2ee5634dac4..af4fe6f7ce7 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -20620,6 +20620,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/invokedynamic/lambdas"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test + @TestMetadata("kt52875.kt") + public void testKt52875() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/lambdas/kt52875.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/invokedynamic/lambdas/inlineClassInSignature") @TestDataPath("$PROJECT_ROOT") diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 4d55c7afbf9..5397adbe8d2 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -18276,6 +18276,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/invokedynamic/lambdas"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); } + @TestMetadata("kt52875.kt") + public void testKt52875() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/lambdas/kt52875.kt"); + } + @TestMetadata("compiler/testData/codegen/box/invokedynamic/lambdas/inlineClassInSignature") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index b714262fcc8..2f8293ead7c 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -23305,6 +23305,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/invokedynamic/lambdas"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); } + @Test + @TestMetadata("kt52875.kt") + public void testKt52875() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/lambdas/kt52875.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/invokedynamic/lambdas/inlineClassInSignature") @TestDataPath("$PROJECT_ROOT")