From a214d6156777c78470a480dc5a511f76b4ad065f Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Mon, 18 Nov 2019 10:12:20 +0100 Subject: [PATCH] IR. Change visibility to lowered default function/constructors to public --- .../lower/DefaultArgumentStubGenerator.kt | 4 +++ .../defaultArguments/noAccessorForDefault.kt | 31 +++++++++++++++++++ .../withDefaultArguments/funInClass.kt | 18 +++++++++-- .../codegen/BytecodeTextTestGenerated.java | 5 +++ .../ir/IrBytecodeTextTestGenerated.java | 5 +++ 5 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/codegen/bytecodeText/defaultArguments/noAccessorForDefault.kt diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt index dc83a08e238..4436602520c 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/DefaultArgumentStubGenerator.kt @@ -9,6 +9,8 @@ import org.jetbrains.kotlin.backend.common.* import org.jetbrains.kotlin.backend.common.descriptors.* import org.jetbrains.kotlin.backend.common.ir.* import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.builders.* import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter @@ -361,6 +363,7 @@ private fun IrFunction.generateDefaultsFunctionImpl(context: CommonBackendContex isExternal = false isPrimary = false isExpect = false + visibility = Visibilities.PUBLIC } is IrSimpleFunction -> buildFunWithDescriptorForInlining(descriptor) { @@ -370,6 +373,7 @@ private fun IrFunction.generateDefaultsFunctionImpl(context: CommonBackendContex modality = Modality.FINAL isExternal = false isTailrec = false + visibility = Visibilities.PUBLIC } else -> throw IllegalStateException("Unknown function type") } diff --git a/compiler/testData/codegen/bytecodeText/defaultArguments/noAccessorForDefault.kt b/compiler/testData/codegen/bytecodeText/defaultArguments/noAccessorForDefault.kt new file mode 100644 index 00000000000..3fca72cbc5f --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/defaultArguments/noAccessorForDefault.kt @@ -0,0 +1,31 @@ +// FILE: Foo.kt + +package foo + +open class Foo() { + protected fun foo(value: Boolean = false) = if (!value) "OK" else "fail5" +} + +// FILE: Bar.kt + +package bar + +import foo.Foo + +class Bar() : Foo() { + fun execute(): String { + return object { fun test() = foo() }.test () + } +} + +fun box(): String { + return Bar().execute() +} + +// @bar/Bar.class: +// 0 access\$ +// 0 INVOKESTATIC foo/Foo.foo\$default + +// @bar/Bar$execute$1.class: +// 0 access\$ +// 1 INVOKESTATIC foo/Foo.foo\$default \ No newline at end of file diff --git a/compiler/testData/writeFlags/function/withDefaultArguments/funInClass.kt b/compiler/testData/writeFlags/function/withDefaultArguments/funInClass.kt index df31e2d9afa..ec789fa1fec 100644 --- a/compiler/testData/writeFlags/function/withDefaultArguments/funInClass.kt +++ b/compiler/testData/writeFlags/function/withDefaultArguments/funInClass.kt @@ -1,7 +1,19 @@ -class MyClass() { - fun test(s: String = "") {} +open class MyClass() { + fun testPublic(s: String = "") {} + + protected fun testProtected(s: String = "") {} + + private fun testPrivate(s: String = "") {} } // TESTED_OBJECT_KIND: function -// TESTED_OBJECTS: MyClass, test$default +// TESTED_OBJECTS: MyClass, testPublic$default // FLAGS: ACC_PUBLIC, ACC_STATIC, ACC_SYNTHETIC + +// TESTED_OBJECT_KIND: function +// TESTED_OBJECTS: MyClass, testProtected$default +// FLAGS: ACC_PUBLIC, ACC_STATIC, ACC_SYNTHETIC + +// TESTED_OBJECT_KIND: function +// TESTED_OBJECTS: MyClass, testPrivate$default +// FLAGS: ACC_PUBLIC, ACC_STATIC, ACC_SYNTHETIC \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 555fc6d1498..a67cc942d67 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -1580,6 +1580,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/defaultArguments/methodHandlerElimination.kt"); } + @TestMetadata("noAccessorForDefault.kt") + public void testNoAccessorForDefault() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/defaultArguments/noAccessorForDefault.kt"); + } + @TestMetadata("noEmptyArray.kt") public void testNoEmptyArray() throws Exception { runTest("compiler/testData/codegen/bytecodeText/defaultArguments/noEmptyArray.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java index d6834e93c5f..cba11b38969 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -1535,6 +1535,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/defaultArguments/methodHandlerElimination.kt"); } + @TestMetadata("noAccessorForDefault.kt") + public void testNoAccessorForDefault() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/defaultArguments/noAccessorForDefault.kt"); + } + @TestMetadata("noEmptyArray.kt") public void testNoEmptyArray() throws Exception { runTest("compiler/testData/codegen/bytecodeText/defaultArguments/noEmptyArray.kt");