From e9946b21b5bafa3cb42487fe9311485e57cfcb38 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 29 Nov 2019 19:33:20 +0100 Subject: [PATCH] JVM IR: do not hide constructor with inline class types and defaults This corresponds to the ABI generated by the old backend. Moreover, when compiling the module 'ir.tree' with JVM IR (could not reproduce on a small sample), this led to a codegen crash when trying to reassign parameter value to the default stub, which is an error expression and can't be generated by ExpressionCodegen. --- .../org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt | 3 ++- .../inlineClasses/constructorWithDefaultArguments.kt | 11 +++++++++++ .../kotlin/codegen/BytecodeTextTestGenerated.java | 5 +++++ .../codegen/ir/IrBytecodeTextTestGenerated.java | 5 +++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/bytecodeText/inlineClasses/constructorWithDefaultArguments.kt diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt index e505b1926be..6104c126cd1 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt @@ -115,7 +115,8 @@ val IrStatementOrigin?.isLambda: Boolean get() = this == IrStatementOrigin.LAMBDA || this == IrStatementOrigin.ANONYMOUS_FUNCTION val IrConstructor.shouldBeHidden: Boolean - get() = !Visibilities.isPrivate(visibility) && !constructedClass.isInline && hasMangledParameters + get() = !Visibilities.isPrivate(visibility) && !constructedClass.isInline && hasMangledParameters && + origin != IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER // An IR builder with a reference to the JvmBackendContext class JvmIrBuilder( diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/constructorWithDefaultArguments.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/constructorWithDefaultArguments.kt new file mode 100644 index 00000000000..f86c0647508 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/constructorWithDefaultArguments.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: +InlineClasses + +inline class A(val s: String) + +class B(x: Long, a: A = A("OK")) + +// @B.class: +// 1 private \(JLjava/lang/String;\)V +// 1 public synthetic \(JLjava/lang/String;Lkotlin/jvm/internal/DefaultConstructorMarker;\)V +// 1 public synthetic \(JLjava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;\)V +// 0 \(JLjava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;Lkotlin/jvm/internal/DefaultConstructorMarker;\)V diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 8da7dba167f..18f53aad313 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -2577,6 +2577,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/constructorBridge.kt"); } + @TestMetadata("constructorWithDefaultArguments.kt") + public void testConstructorWithDefaultArguments() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/inlineClasses/constructorWithDefaultArguments.kt"); + } + @TestMetadata("defaultParametersDontBox.kt") public void testDefaultParametersDontBox() throws Exception { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/defaultParametersDontBox.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java index a593dd570d6..e87d2303f54 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -2622,6 +2622,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/constructorBridge.kt"); } + @TestMetadata("constructorWithDefaultArguments.kt") + public void testConstructorWithDefaultArguments() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/inlineClasses/constructorWithDefaultArguments.kt"); + } + @TestMetadata("defaultParametersDontBox.kt") public void testDefaultParametersDontBox() throws Exception { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/defaultParametersDontBox.kt");