Generate private constructor for object

#KT-9510 Fixed
This commit is contained in:
Michael Bogdanov
2015-10-08 16:53:01 +03:00
parent a3e0205aec
commit 8198ac77cb
9 changed files with 24 additions and 9 deletions
@@ -365,7 +365,7 @@ public class AsmUtil {
// the following code is only for PRIVATE visibility of member
if (memberDescriptor instanceof ConstructorDescriptor) {
if (isNonCompanionObject(containingDeclaration) || isEnumEntry(containingDeclaration)) {
if (isEnumEntry(containingDeclaration)) {
return NO_FLAG_PACKAGE_PRIVATE;
}
if (isEnumClass(containingDeclaration)) {
@@ -395,8 +395,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
}
public void recordSyntheticAccessorIfNeeded(@NotNull CallableMemberDescriptor descriptor, @NotNull BindingContext bindingContext) {
if (hasThisDescriptor() &&
(descriptor instanceof ConstructorDescriptor || Boolean.TRUE.equals(bindingContext.get(NEED_SYNTHETIC_ACCESSOR, descriptor)))) {
if (hasThisDescriptor() && Boolean.TRUE.equals(bindingContext.get(NEED_SYNTHETIC_ACCESSOR, descriptor))) {
// Not a super call because neither constructors nor private members can be targets of super calls
accessibleDescriptorIfNeeded(descriptor, /* superCallExpression = */ null);
}
@@ -17,5 +17,5 @@ public final class A {
public final int f() { /* compiled code */ }
A() { /* compiled code */ }
}
private A() { /* compiled code */ }
}
@@ -0,0 +1,10 @@
public open class Outer private constructor(val s: String) {
companion object {
fun test () = { Outer("OK") }()
}
}
fun box(): String {
return Outer.test().s
}
@@ -4,4 +4,4 @@ class A {
}
}
// A and companion object constructor call
// 4 ALOAD 0
// 3 ALOAD 0
@@ -4,5 +4,5 @@ class A {
}
}
// A and companion object constructor call
// 4 ALOAD 0
// 3 ALOAD 0
// 1 synthetic access\$getR
@@ -5,4 +5,4 @@ class Foo {
// TESTED_OBJECT_KIND: function
// TESTED_OBJECTS: Foo$Test, <init>
// FLAGS:
// FLAGS: ACC_PRIVATE
@@ -4,4 +4,4 @@ object Foo {
// TESTED_OBJECT_KIND: function
// TESTED_OBJECTS: Foo, <init>
// FLAGS:
// FLAGS: ACC_PRIVATE
@@ -6415,6 +6415,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("captured.kt")
public void testCaptured() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/privateConstructors/captured.kt");
doTest(fileName);
}
@TestMetadata("companion.kt")
public void testCompanion() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/privateConstructors/companion.kt");