diff --git a/compiler/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleGenerationExt.kt b/compiler/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleGenerationExt.kt index cfe9433..79f9afc 100644 --- a/compiler/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleGenerationExt.kt +++ b/compiler/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleGenerationExt.kt @@ -53,9 +53,14 @@ fun generateClassModule(classFile: OutputStream, module: KoinMetaData.Module) { module.includes?.let { includes -> if (includes.isNotEmpty()) { generateIncludes(includes, classFile) } } - - if (module.definitions.isNotEmpty()){ - if (module.definitions.any { it is KoinMetaData.Definition.FunctionDefinition }) { + + if (module.definitions.isNotEmpty()) { + if (module.definitions.any { + // if any definition is a class function, we need to instantiate the module instance + // to able to call the function on this instance. + it is KoinMetaData.Definition.FunctionDefinition && + it.isClassFunction + }) { classFile.appendText("${NEW_LINE}val moduleInstance = $modulePath()") }