Fix for KT-10881 Declaring constant in a mutlifile class causes an IllegalAccessError on its usage.
Generate fields for 'const' properties in facade class. NB reading annotations for 'const' vals in multifile class doesn't work, KT-10892.
This commit is contained in:
@@ -114,7 +114,7 @@ public class PropertyCodegen {
|
||||
assert kind == OwnerKind.PACKAGE || kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.DEFAULT_IMPLS
|
||||
: "Generating property with a wrong kind (" + kind + "): " + descriptor;
|
||||
|
||||
if (CodegenContextUtil.isImplClassOwner(context)) {
|
||||
if (isBackingFieldOwner(descriptor)) {
|
||||
assert declaration != null : "Declaration is null for different context: " + context;
|
||||
|
||||
genBackingFieldAndAnnotations(declaration, descriptor, false);
|
||||
@@ -128,6 +128,13 @@ public class PropertyCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isBackingFieldOwner(@NotNull PropertyDescriptor descriptor) {
|
||||
if (descriptor.isConst()) {
|
||||
return !(context instanceof MultifileClassPartContext);
|
||||
}
|
||||
return CodegenContextUtil.isImplClassOwner(context);
|
||||
}
|
||||
|
||||
private void genBackingFieldAndAnnotations(@NotNull KtNamedDeclaration declaration, @NotNull PropertyDescriptor descriptor, boolean isParameter) {
|
||||
boolean hasBackingField = hasBackingField(declaration, descriptor);
|
||||
boolean hasDelegate = declaration instanceof KtProperty && ((KtProperty) declaration).hasDelegate();
|
||||
|
||||
@@ -159,7 +159,7 @@ public class JetTypeMapper {
|
||||
if (file != null) {
|
||||
Visibility visibility = descriptor.getVisibility();
|
||||
if (!publicFacade ||
|
||||
descriptor instanceof PropertyDescriptor ||
|
||||
isNonConstProperty(descriptor) ||
|
||||
Visibilities.isPrivate(visibility) ||
|
||||
isAccessor/*Cause of KT-9603*/
|
||||
) {
|
||||
@@ -181,6 +181,12 @@ public class JetTypeMapper {
|
||||
" in package fragment " + descriptor.getContainingDeclaration());
|
||||
}
|
||||
|
||||
private static boolean isNonConstProperty(@NotNull CallableMemberDescriptor descriptor) {
|
||||
if (!(descriptor instanceof PropertyDescriptor)) return false;
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
return !propertyDescriptor.isConst();
|
||||
}
|
||||
|
||||
public static class ContainingClassesInfo {
|
||||
private final ClassId facadeClassId;
|
||||
private final ClassId implClassId;
|
||||
|
||||
Reference in New Issue
Block a user