JVM: Don't generate accessors to companions in earlier language versions

This commit is contained in:
Dmitry Petrov
2020-01-13 23:37:53 +03:00
parent 6ad159bb01
commit a16b21a7cc
5 changed files with 49 additions and 1 deletions
@@ -2862,7 +2862,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
}
}
private static CodegenContext getContextForCompanionObjectAccessorIfRequiredOrNull(
private CodegenContext getContextForCompanionObjectAccessorIfRequiredOrNull(
@NotNull ClassDescriptor companionObjectDescriptor,
@NotNull CodegenContext contextBeforeInline
) {
@@ -2870,6 +2870,10 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
return null;
}
if (!state.getLanguageVersionSettings().supportsFeature(LanguageFeature.ProperVisibilityForCompanionObjectInstanceField)) {
return null;
}
int accessFlag = AsmUtil.getVisibilityAccessFlag(companionObjectDescriptor);
CodegenContext context = contextBeforeInline.getFirstCrossInlineOrNonInlineContext();
@@ -0,0 +1,13 @@
// !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField
// IGNORE_BACKEND: JVM_IR
// ^ TODO implement ProperVisibilityForCompanionObjectInstanceField feature support in JMV_IR
class Host {
private companion object {
fun foo() = 1
}
fun test() = { foo() }
}
// 1 synthetic access\$
@@ -0,0 +1,11 @@
// !LANGUAGE: -ProperVisibilityForCompanionObjectInstanceField
class Host {
private companion object {
fun foo() = 1
}
fun test() = { foo() }
}
// 0 synthetic access\$
@@ -920,6 +920,16 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
public void testKt14258_5() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/companion/kt14258_5.kt");
}
@TestMetadata("privateCompanionObjectAccessors_after.kt")
public void testPrivateCompanionObjectAccessors_after() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_after.kt");
}
@TestMetadata("privateCompanionObjectAccessors_before.kt")
public void testPrivateCompanionObjectAccessors_before() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_before.kt");
}
}
@TestMetadata("compiler/testData/codegen/bytecodeText/conditions")
@@ -920,6 +920,16 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
public void testKt14258_5() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/companion/kt14258_5.kt");
}
@TestMetadata("privateCompanionObjectAccessors_after.kt")
public void testPrivateCompanionObjectAccessors_after() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_after.kt");
}
@TestMetadata("privateCompanionObjectAccessors_before.kt")
public void testPrivateCompanionObjectAccessors_before() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/companion/privateCompanionObjectAccessors_before.kt");
}
}
@TestMetadata("compiler/testData/codegen/bytecodeText/conditions")