Open kmbisset89 opened 2 months ago
Same issue
Not using includes() and writing all modules in the same file solved the problem, but... It's quite dirty
@arnaudgiuliani
@OptIn(KoinInternalApi::class)
fun flatten(modules: List<Module>): Set<Module> {
// This is actually a DFS traversal of the module graph,
// but we're using a stack instead of recursion to avoid stack overflows and performance overhead.
val flatten = linkedSetOf<Module>()
// I added a filter not null to get ride of this even though it should not be possible to have a null in that list.
val stack = ArrayDeque(modules.asReversed().filterNotNull())
while (stack.isNotEmpty()) {
/* The problem is here some how it is getting a null module */
val current = stack.removeLast()
// If the module is already in the set, that means we've already visited it, so we can skip it.
if (!flatten.add(current)) {
continue
}
// Add all the included modules to the stack if they haven't been visited yet.
for (module in current.includedModules) {
if (module !in flatten) {
stack += module
}
}
}
return flatten
}
Getting an error when using submodules that throws an exception.
To Reproduce Steps to reproduce the behavior: Use the includes keyword: val commonModule = module { includes(infrastructureModule, viewModels, useCases, repositories) }
private val infrastructureModule = module { single { CoroutineErrorCatcher(get()) }
}
private val viewModels = module {
}
private val useCases = module {
}
private val repositories = module {
}
Expected behavior Not throw exception
Koin module and version: