xxfast
12/21/2021, 10:13 AMThread 1: EXC_BAD_ACCESS (code=1, address=0x10)
with very little output from the console as to why. Its pointing to this
App`kfun:org.koin.core.module.Module#<get-mappings>(){}kotlin.collections.HashMap<kotlin.String,org.koin.core.instance.InstanceFactory<*>>:
Has anyone encountered this before?xxfast
12/21/2021, 12:58 PM:login
and :app
.
:app
has this file AppModules.kt
val appModules: List<Module> = listOf(
..
loginViewModelsModule,
appViewModelsModule,
)
where, loginViewModelsModule
is defined in :login
commonMain
as an
expect val loginViewModelsModule: Module
and appViewModelsModule
is defined in :app
commonMain
as
expect val appViewModelsModule: Module
In order to debug the above runtime crash, i commented out appViewModelsModule
like
val appModules: List<Module> = listOf(
..
loginViewModelsModule,
// appViewModelsModule,
)
which worked, so I thought its something to do with how i defined this particular module. So i made the module empty in iosMain
actual val appViewModelsModule: Module = module { }
but even then it was still crashing with the same ambiguous error.
This was pretty much a road-block - so then I decided to define the module on the same file in AppModules.kt
then it dawned on me
expect val appViewModelsModule: Module
val appModules: List<Module> = listOf(
..
loginViewModelsModule,
appViewModelsModule, // Compilation error, variable must be initialised
)
Looks like kotlin compiler is okay with expect
top level members from external modules being not initialised, but somehow not okay with the expect
top level members from within the same module.
Am i going crazy, or doesn’t this sound like a kotlin-compiler bug 🤔?xxfast
12/21/2021, 1:09 PMactual val appViewModelsModules: Module get() =
module {
single { MainViewModel() }
single { RootViewModel() }
}
and that worked just fine