diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt index e1f3d2d917d..77fb95729f8 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt @@ -90,7 +90,10 @@ class AnonymousObjectTransformer( val node = MethodNode(access, name, desc, signature, exceptions) if (name == "") { if (constructor != null) { - throw RuntimeException("Lambda, SAM or anonymous object should have only one constructor") + throw RuntimeException( + "Lambda, SAM or anonymous object should have only one constructor.\n" + + "First:\n${constructor.nodeText}\n\nSecond:\n${node.nodeText}\n" + ) } constructor = node } else { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxInlineCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxInlineCodegenTestGenerated.java index 3e8f3abdd24..1bee3c1f65a 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxInlineCodegenTestGenerated.java @@ -2244,6 +2244,12 @@ public class FirBlackBoxInlineCodegenTestGenerated extends AbstractFirBlackBoxIn KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("anonymousObject.kt") + public void testAnonymousObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/inlineClasses/anonymousObject.kt"); + } + @Test @TestMetadata("inlineClassWithInlineValReturningInlineClass.kt") public void testInlineClassWithInlineValReturningInlineClass() throws Exception { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt index a3cb675b7c4..973a1a77445 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt @@ -229,8 +229,9 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle val constructedClass = constructedClass - if (!DescriptorVisibilities.isPrivate(visibility) && !constructedClass.isInline && hasMangledParameters) - return true + if (!DescriptorVisibilities.isPrivate(visibility) && !constructedClass.isInline && hasMangledParameters && + !constructedClass.isAnonymousObject + ) return true if (visibility != DescriptorVisibilities.PUBLIC && constructedClass.modality == Modality.SEALED) return true diff --git a/compiler/testData/codegen/boxInline/inlineClasses/anonymousObject.kt b/compiler/testData/codegen/boxInline/inlineClasses/anonymousObject.kt new file mode 100644 index 00000000000..b1d2e56b616 --- /dev/null +++ b/compiler/testData/codegen/boxInline/inlineClasses/anonymousObject.kt @@ -0,0 +1,16 @@ +// NO_CHECK_LAMBDA_INLINING +// FILE: 1.kt + +package test + +inline class IC(val value: Any) + +inline fun f(a: IC): () -> T = { + a.value as T +} + +// FILE: 2.kt + +import test.* + +fun box(): String = f(IC("OK"))() diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxInlineCodegenTestGenerated.java index 4bbf6aaa6cf..e58203d76d6 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -2244,6 +2244,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @Test + @TestMetadata("anonymousObject.kt") + public void testAnonymousObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/inlineClasses/anonymousObject.kt"); + } + @Test @TestMetadata("inlineClassWithInlineValReturningInlineClass.kt") public void testInlineClassWithInlineValReturningInlineClass() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index cd25eee936b..9470fe0531e 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -2244,6 +2244,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @Test + @TestMetadata("anonymousObject.kt") + public void testAnonymousObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/inlineClasses/anonymousObject.kt"); + } + @Test @TestMetadata("inlineClassWithInlineValReturningInlineClass.kt") public void testInlineClassWithInlineValReturningInlineClass() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxInlineCodegenTestGenerated.java index 8489888393a..9fb6095ddf9 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxInlineCodegenTestGenerated.java @@ -2244,6 +2244,12 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("anonymousObject.kt") + public void testAnonymousObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/inlineClasses/anonymousObject.kt"); + } + @Test @TestMetadata("inlineClassWithInlineValReturningInlineClass.kt") public void testInlineClassWithInlineValReturningInlineClass() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrCompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrCompileKotlinAgainstInlineKotlinTestGenerated.java index d1a19baf1e7..55e41322306 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -2244,6 +2244,12 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("anonymousObject.kt") + public void testAnonymousObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/inlineClasses/anonymousObject.kt"); + } + @Test @TestMetadata("inlineClassWithInlineValReturningInlineClass.kt") public void testInlineClassWithInlineValReturningInlineClass() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxInlineTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxInlineTestGenerated.java index ce4ed6b602c..e42ec5e9820 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxInlineTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmIrAgainstOldBoxInlineTestGenerated.java @@ -2244,6 +2244,12 @@ public class JvmIrAgainstOldBoxInlineTestGenerated extends AbstractJvmIrAgainstO KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_MULTI_MODULE_IR_AGAINST_OLD, true); } + @Test + @TestMetadata("anonymousObject.kt") + public void testAnonymousObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/inlineClasses/anonymousObject.kt"); + } + @Test @TestMetadata("inlineClassWithInlineValReturningInlineClass.kt") public void testInlineClassWithInlineValReturningInlineClass() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxInlineTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxInlineTestGenerated.java index 3b646a4262f..6f7e9d3cc2b 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxInlineTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/JvmOldAgainstIrBoxInlineTestGenerated.java @@ -2244,6 +2244,12 @@ public class JvmOldAgainstIrBoxInlineTestGenerated extends AbstractJvmOldAgainst KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_MULTI_MODULE_OLD_AGAINST_IR, true); } + @Test + @TestMetadata("anonymousObject.kt") + public void testAnonymousObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/inlineClasses/anonymousObject.kt"); + } + @Test @TestMetadata("inlineClassWithInlineValReturningInlineClass.kt") public void testInlineClassWithInlineValReturningInlineClass() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenInlineES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenInlineES6TestGenerated.java index 47fd9bacfb7..41bff6fe402 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenInlineES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenInlineES6TestGenerated.java @@ -1795,6 +1795,11 @@ public class IrJsCodegenInlineES6TestGenerated extends AbstractIrJsCodegenInline KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true); } + @TestMetadata("anonymousObject.kt") + public void testAnonymousObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/inlineClasses/anonymousObject.kt"); + } + @TestMetadata("inlineClassWithInlineValReturningInlineClass.kt") public void testInlineClassWithInlineValReturningInlineClass() throws Exception { runTest("compiler/testData/codegen/boxInline/inlineClasses/inlineClassWithInlineValReturningInlineClass.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenInlineTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenInlineTestGenerated.java index 022c5e3c219..5d7d9b55532 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenInlineTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenInlineTestGenerated.java @@ -1795,6 +1795,11 @@ public class IrJsCodegenInlineTestGenerated extends AbstractIrJsCodegenInlineTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } + @TestMetadata("anonymousObject.kt") + public void testAnonymousObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/inlineClasses/anonymousObject.kt"); + } + @TestMetadata("inlineClassWithInlineValReturningInlineClass.kt") public void testInlineClassWithInlineValReturningInlineClass() throws Exception { runTest("compiler/testData/codegen/boxInline/inlineClasses/inlineClassWithInlineValReturningInlineClass.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenInlineTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenInlineTestGenerated.java index c6ceb1eb10d..9e8111be9fa 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenInlineTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenInlineTestGenerated.java @@ -1795,6 +1795,11 @@ public class JsCodegenInlineTestGenerated extends AbstractJsCodegenInlineTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/inlineClasses"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); } + @TestMetadata("anonymousObject.kt") + public void testAnonymousObject() throws Exception { + runTest("compiler/testData/codegen/boxInline/inlineClasses/anonymousObject.kt"); + } + @TestMetadata("inlineClassWithInlineValReturningInlineClass.kt") public void testInlineClassWithInlineValReturningInlineClass() throws Exception { runTest("compiler/testData/codegen/boxInline/inlineClasses/inlineClassWithInlineValReturningInlineClass.kt");