diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/context/CodegenContext.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/context/CodegenContext.java index 252a9003581..7004ec47492 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/context/CodegenContext.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/context/CodegenContext.java @@ -282,11 +282,7 @@ public abstract class CodegenContext { } 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) { + if (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); diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CliLightClassGenerationSupport.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CliLightClassGenerationSupport.kt index b5eb14c301f..b0716d309ed 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CliLightClassGenerationSupport.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CliLightClassGenerationSupport.kt @@ -80,11 +80,13 @@ public class CliLightClassGenerationSupport(project: Project) : LightClassGenera } override fun getContextForPackage(files: Collection): LightClassConstructionContext { - return getContext() + return LightClassConstructionContext(bindingContext, module) } override fun getContextForClassOrObject(classOrObject: KtClassOrObject): LightClassConstructionContext { - return getContext() + //force resolve companion for light class generation + bindingContext.get(BindingContext.CLASS, classOrObject)?.companionObjectDescriptor + return LightClassConstructionContext(bindingContext, module) } private fun getContext(): LightClassConstructionContext {