koin icon indicating copy to clipboard operation
koin copied to clipboard

Koin Annotations failing when module function return type is nullable

Open hellosagar opened this issue 1 year ago • 0 comments

Describe the bug I'm using Koin Annotations. I have a NetworkModule class, and when I assemble the APK, I get an error when the return type is currently nullable string. However, when I change the return type to non-nullable String, it works fine.

To Reproduce Take the snippets from the below on your machine and try to assemble the APK; Koin will throw an error.

Expected behaviour On assembling the APK, it should work for nullable return types, too.

Koin module and version: io.insert-koin:koin-bom:4.0.0 io.insert-koin:koin-annotations-bom:1.4.0-RC4 ksp("io.insert-koin:koin-ksp-compiler:1.4.0-RC4")

Snippet or Sample project to help reproduce

@Module
@ComponentScan("foo.bar.sugar")
class NetworkModule {

@Single
    @Named("appDeviceName")
    fun provideDeviceName(
        context: Context,
        @Named("appSettingsSharedPreferences") sharedPref: SharedPreferences,
    ): String? {
        return sharedPref.getString(context.getString(R.string.settings_device_name_key), null)
    }

    @Single
    @Named("appDeviceLocation")
    fun provideDeviceLocation(
        context: Context,
        @Named("appSettingsSharedPreferences") sharedPref: SharedPreferences
    ): String? {
        return sharedPref.getString(context.getString(R.string.settings_device_location_key), null)
    }
}

Error

> Task :app:compileDebugKotlin FAILED
e: file:///Users/sagarkhurana/StudioProjects/ehub-android/app/build/generated/ksp/debug/kotlin/org/koin/ksp/generated/NetworkModuleGencom$viaeurope$ehub$di.kt:11:227 None of the following candidates is applicable:
@OptionDslMarker() fun <S : Any> KoinDefinition<out S>.bind(clazz: KClass<S>): KoinDefinition<out S>
@OptionDslMarker() fun <reified S : Any> KoinDefinition<out S>.bind(): KoinDefinition<out S>
e: file:///Users/sagarkhurana/StudioProjects/ehub-android/app/build/generated/ksp/debug/kotlin/org/koin/ksp/generated/NetworkModuleGencom$viaeurope$ehub$di.kt:12:235 None of the following candidates is applicable:
@OptionDslMarker() fun <S : Any> KoinDefinition<out S>.bind(clazz: KClass<S>): KoinDefinition<out S>
@OptionDslMarker() fun <reified S : Any> KoinDefinition<out S>.bind(): KoinDefinition<out S>

Generated DSL

single(qualifier=org.koin.core.qualifier.StringQualifier("appDeviceName")) { moduleInstance.provideDeviceName(context=get(),sharedPref=get(qualifier=org.koin.core.qualifier.StringQualifier("appSettingsSharedPreferences"))) } bind(kotlin.String::class)
single(qualifier=org.koin.core.qualifier.StringQualifier("appDeviceLocation")) { moduleInstance.provideDeviceLocation(context=get(),sharedPref=get(qualifier=org.koin.core.qualifier.StringQualifier("appSettingsSharedPreferences"))) } bind(kotlin.String::class)

hellosagar avatar Oct 08 '24 05:10 hellosagar