Generate proper visibility for companion object instance field in LV1.3+
This commit is contained in:
@@ -839,11 +839,18 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
@Nullable KtObjectDeclaration companionObject = CollectionsKt.firstOrNull(myClass.getCompanionObjects());
|
||||
|
||||
int properFieldVisibilityFlag = getVisibilityAccessFlag(companionObjectDescriptor);
|
||||
boolean deprecatedFieldForInvisibleCompanionObject =
|
||||
state.getLanguageVersionSettings().supportsFeature(LanguageFeature.DeprecatedFieldForInvisibleCompanionObject);
|
||||
boolean properVisibilityForCompanionObjectInstanceField =
|
||||
state.getLanguageVersionSettings().supportsFeature(LanguageFeature.ProperVisibilityForCompanionObjectInstanceField);
|
||||
boolean fieldShouldBeDeprecated =
|
||||
state.getLanguageVersionSettings().supportsFeature(LanguageFeature.DeprecatedFieldForInvisibleCompanionObject) &&
|
||||
deprecatedFieldForInvisibleCompanionObject &&
|
||||
!properVisibilityForCompanionObjectInstanceField &&
|
||||
(properFieldVisibilityFlag & (ACC_PRIVATE | ACC_PROTECTED)) != 0;
|
||||
// TODO generate field with proper visibility in language version 1.3
|
||||
int fieldAccessFlags = ACC_PUBLIC | ACC_STATIC | ACC_FINAL;
|
||||
if (properVisibilityForCompanionObjectInstanceField) {
|
||||
fieldAccessFlags |= properFieldVisibilityFlag;
|
||||
}
|
||||
if (fieldShouldBeDeprecated) {
|
||||
fieldAccessFlags |= ACC_DEPRECATED;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// LANGUAGE_VERSION: 1.2
|
||||
// LANGUAGE_VERSION: 1.3
|
||||
|
||||
class TestPrivateCompanion {
|
||||
private companion object Test
|
||||
|
||||
@@ -22,7 +22,7 @@ final class TestPrivateCompanion$Test {
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class TestPrivateCompanion {
|
||||
public deprecated final static @java.lang.Deprecated field Test: TestPrivateCompanion$Test
|
||||
public private final static field Test: TestPrivateCompanion$Test
|
||||
inner class TestPrivateCompanion$Test
|
||||
static method <clinit>(): void
|
||||
public method <init>(): void
|
||||
@@ -37,7 +37,7 @@ public final class TestProtectedCompanion$Test {
|
||||
|
||||
@kotlin.Metadata
|
||||
public class TestProtectedCompanion {
|
||||
public deprecated final static @java.lang.Deprecated field Test: TestProtectedCompanion$Test
|
||||
public protected final static field Test: TestProtectedCompanion$Test
|
||||
inner class TestProtectedCompanion$Test
|
||||
static method <clinit>(): void
|
||||
public method <init>(): void
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// LANGUAGE_VERSION: 1.2
|
||||
|
||||
class TestPrivateCompanion {
|
||||
private companion object Test
|
||||
}
|
||||
|
||||
open class TestProtectedCompanion {
|
||||
protected companion object Test
|
||||
}
|
||||
|
||||
class TestInternalCompanion {
|
||||
internal companion object Test
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
@kotlin.Metadata
|
||||
public final class TestInternalCompanion$Test {
|
||||
inner class TestInternalCompanion$Test
|
||||
private method <init>(): void
|
||||
public synthetic method <init>(p0: kotlin.jvm.internal.DefaultConstructorMarker): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class TestInternalCompanion {
|
||||
public final static field Test: TestInternalCompanion$Test
|
||||
inner class TestInternalCompanion$Test
|
||||
static method <clinit>(): void
|
||||
public method <init>(): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
final class TestPrivateCompanion$Test {
|
||||
inner class TestPrivateCompanion$Test
|
||||
private method <init>(): void
|
||||
public synthetic method <init>(p0: kotlin.jvm.internal.DefaultConstructorMarker): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class TestPrivateCompanion {
|
||||
public deprecated final static @java.lang.Deprecated field Test: TestPrivateCompanion$Test
|
||||
inner class TestPrivateCompanion$Test
|
||||
static method <clinit>(): void
|
||||
public method <init>(): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class TestProtectedCompanion$Test {
|
||||
inner class TestProtectedCompanion$Test
|
||||
private method <init>(): void
|
||||
public synthetic method <init>(p0: kotlin.jvm.internal.DefaultConstructorMarker): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public class TestProtectedCompanion {
|
||||
public deprecated final static @java.lang.Deprecated field Test: TestProtectedCompanion$Test
|
||||
inner class TestProtectedCompanion$Test
|
||||
static method <clinit>(): void
|
||||
public method <init>(): void
|
||||
}
|
||||
@@ -108,6 +108,12 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("invisibleCompanionObject_lv12.kt")
|
||||
public void testInvisibleCompanionObject_lv12() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/invisibleCompanionObject_lv12.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jvmOverloadsAndParametersAnnotations.kt")
|
||||
public void testJvmOverloadsAndParametersAnnotations() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/jvmOverloadsAndParametersAnnotations.kt");
|
||||
|
||||
@@ -74,6 +74,7 @@ enum class LanguageFeature(
|
||||
ProhibitDataClassesOverridingCopy(KOTLIN_1_3),
|
||||
RestrictionOfWrongAnnotationsWithUseSiteTargetsOnTypes(KOTLIN_1_3),
|
||||
ProhibitInnerClassesOfGenericClassExtendingThrowable(KOTLIN_1_3),
|
||||
ProperVisibilityForCompanionObjectInstanceField(KOTLIN_1_3),
|
||||
|
||||
StrictJavaNullabilityAssertions(sinceVersion = null, defaultState = State.DISABLED),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user