Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to inject @JvmInline value classes #2930

Open
drinkthestars opened this issue Oct 11, 2021 · 9 comments
Open

Unable to inject @JvmInline value classes #2930

drinkthestars opened this issue Oct 11, 2021 · 9 comments

Comments

@drinkthestars
Copy link

Injecting a @JvmInline value class fails in the following manner:

Code:

@JvmInline value class Foo(val value: Int)

@Module
@InstallIn(SingletonComponent::class)
object FooModule {
    @Provides
    fun provideFoo() = Foo(value = 123)
}

class FooBar @Inject constructor(
    private val foo: Foo
) { /** ... **/ }

class UsesFooBar @Inject constructor(
    private val fooBar: FooBar
) { /** Uses fooBar **/ }

Fails with:

[Dagger/MissingBinding] FooBar cannot be provided without an @Inject constructor or an @Provides-annotated method.
  public abstract static class SingletonC implements FooApplication_GeneratedInjector

Not sure if this is a bug, or if it's just impossible to support with kapt (i.e. needs something like KSP) 🤔. Thanks!

@drinkthestars
Copy link
Author

could be related to #2855

@Chang-Eric
Copy link
Member

I think this will likely be something that needs KSP as we probably will just see Foo as an Integer after kapt. Added some labels but we can revisit in the future when KSP is done.

@drinkthestars
Copy link
Author

Sounds good, thank you!

@reddaly
Copy link

reddaly commented Aug 23, 2023

I think this will likely be something that needs KSP as we probably will just see Foo as an Integer after kapt. Added some labels but we can revisit in the future when KSP is done.

Is there a bug I can track related to "when KSP is done?"

@Chang-Eric
Copy link
Member

@reddaly #2349

@bj0
Copy link

bj0 commented Sep 7, 2023

The alpha version of KSP support was released with dagger 1.48, so I tested this again:

@JvmInline
value class PluginContext(val context: Context)



@Module
abstract class UiModule {

...

    companion object {
        @Provides
        @PluginScope
        fun providePluginContext(ctx: Context): PluginContext {
            return PluginContext(ctx)
        }
   }
}  

Just adding this provider (no requesters yet) ksp throws an error:

e: [ksp] java.lang.IllegalArgumentException: not a valid name: UiModule_Companion_ProvidePluginContext-wwunPCQFactory

@Chang-Eric
Copy link
Member

To clarify, KSP is a prerequisite to fixing this, but is not itself the solution.

@dawidhyzy
Copy link

@Chang-Eric is this fixed with the current KSP implementation?

@Chang-Eric
Copy link
Member

It is not fixed, as mentioned above. To clarify in case it is causing confusion, the current behavior is mixed, some cases work, some don't. This is because this is the behavior that existed due to kapt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants