KT-11645 generate backing field for 'private const val' in part implementation class
This commit is contained in:
@@ -142,9 +142,10 @@ public class PropertyCodegen {
|
||||
|
||||
Annotations propertyAnnotations = annotationSplitter.getAnnotationsForTarget(AnnotationUseSiteTarget.PROPERTY);
|
||||
|
||||
// Fields and '$annotations' methods for const properties are generated in the multi-file facade
|
||||
boolean isBackingFieldOwner =
|
||||
descriptor.isConst() ? !(context instanceof MultifileClassPartContext) : CodegenContextUtil.isImplClassOwner(context);
|
||||
// Fields and '$annotations' methods for non-private const properties are generated in the multi-file facade
|
||||
boolean isBackingFieldOwner = descriptor.isConst() && !Visibilities.isPrivate(descriptor.getVisibility())
|
||||
? !(context instanceof MultifileClassPartContext)
|
||||
: CodegenContextUtil.isImplClassOwner(context);
|
||||
|
||||
if (isBackingFieldOwner) {
|
||||
Annotations fieldAnnotations = annotationSplitter.getAnnotationsForTarget(AnnotationUseSiteTarget.FIELD);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// WITH_RUNTIME
|
||||
// FILE: foo.kt
|
||||
@file:JvmName("Util")
|
||||
@file:JvmMultifileClass
|
||||
package test
|
||||
|
||||
private const val x = "O"
|
||||
|
||||
fun foo() = x
|
||||
|
||||
// FILE: bar.kt
|
||||
@file:JvmName("Util")
|
||||
@file:JvmMultifileClass
|
||||
package test
|
||||
|
||||
private const val x = "K"
|
||||
|
||||
fun bar() = x
|
||||
|
||||
// FILE: test.kt
|
||||
package test
|
||||
|
||||
fun box(): String = foo() + bar()
|
||||
@@ -8482,6 +8482,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("privateConstVal.kt")
|
||||
public void testPrivateConstVal() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multifileClasses/privateConstVal.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("samePartNameDifferentFacades.kt")
|
||||
public void testSamePartNameDifferentFacades() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multifileClasses/samePartNameDifferentFacades.kt");
|
||||
|
||||
Reference in New Issue
Block a user