Skip to content

Commit 39d9b35

Browse files
author
Michael Bogdanov
committed
Force resolve companion in light class generation
1 parent a849f3f commit 39d9b35

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

compiler/backend/src/org/jetbrains/kotlin/codegen/context/CodegenContext.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,7 @@ public ClassContext intoClass(ClassDescriptor descriptor, OwnerKind kind, Genera
282282
}
283283
ClassContext classContext = new ClassContext(state.getTypeMapper(), descriptor, kind, this, null);
284284

285-
//We can't call descriptor.getCompanionObjectDescriptor() on light class generation
286-
// because it triggers companion light class generation via putting it to BindingContext.CLASS
287-
// (so MemberCodegen doesn't skip it in genClassOrObject).
288-
if (state.getTypeMapper().getClassBuilderMode() != ClassBuilderMode.LIGHT_CLASSES &&
289-
descriptor.getCompanionObjectDescriptor() != null) {
285+
if (descriptor.getCompanionObjectDescriptor() != null) {
290286
//We need to create companion object context ahead of time
291287
// because otherwise we can't generate synthetic accessor for private members in companion object
292288
classContext.intoClass(descriptor.getCompanionObjectDescriptor(), OwnerKind.IMPLEMENTATION, state);

compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CliLightClassGenerationSupport.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ public class CliLightClassGenerationSupport(project: Project) : LightClassGenera
8080
}
8181

8282
override fun getContextForPackage(files: Collection<KtFile>): LightClassConstructionContext {
83-
return getContext()
83+
return LightClassConstructionContext(bindingContext, module)
8484
}
8585

8686
override fun getContextForClassOrObject(classOrObject: KtClassOrObject): LightClassConstructionContext {
87-
return getContext()
87+
//force resolve companion for light class generation
88+
bindingContext.get(BindingContext.CLASS, classOrObject)?.companionObjectDescriptor
89+
return LightClassConstructionContext(bindingContext, module)
8890
}
8991

9092
private fun getContext(): LightClassConstructionContext {

0 commit comments

Comments
 (0)