Support access to companion private members from nested classes
#KT-5363 Fixed #KT-6804 Fixed
This commit is contained in:
committed by
Max Kammerer
parent
3d88df73e0
commit
d977d29ec4
@@ -206,7 +206,26 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
|
||||
@NotNull
|
||||
public ClassContext intoClass(ClassDescriptor descriptor, OwnerKind kind, GenerationState state) {
|
||||
return new ClassContext(state.getTypeMapper(), descriptor, kind, this, null);
|
||||
if (descriptor.isCompanionObject()) {
|
||||
CodegenContext companionContext = this.findChildContext(descriptor);
|
||||
if (companionContext != null) {
|
||||
assert companionContext.getContextKind() == kind : "Kinds should be same, but: " +
|
||||
companionContext.getContextKind() + "!= " + kind;
|
||||
return (ClassContext) companionContext;
|
||||
}
|
||||
}
|
||||
ClassContext classContext = new ClassContext(state.getTypeMapper(), descriptor, kind, this, null);
|
||||
|
||||
//We can't call descriptor.getCompanionObjectDescriptor() on light class generation
|
||||
// because it triggers companion light class generation via putting it to BindingContext.CLASS
|
||||
// (so MemberCodegen doesn't skip it in genClassOrObject).
|
||||
if (state.getTypeMapper().getClassBuilderMode() != ClassBuilderMode.LIGHT_CLASSES &&
|
||||
descriptor.getCompanionObjectDescriptor() != null) {
|
||||
//We need to create companion object context ahead of time
|
||||
// because otherwise we can't generate synthetic accessor for private members in companion object
|
||||
classContext.intoClass(descriptor.getCompanionObjectDescriptor(), OwnerKind.IMPLEMENTATION, state);
|
||||
}
|
||||
return classContext;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user