Open ursusursus opened 5 months ago
We should probably do better than stackoverflow, however, what's happening here is that there are (unfortunately) multiple ways to declare a subcomponent as a child of another component/subcomponent, and one of those ways is to add a entry point method on the parent component/subcomponent interface that returns the child subcomponent.
So when you add the val what: UserComponent
, you're actually making the UserComponent
a child of SubscriberComponent
, which is what causes the infinite loop.
You can probably work around this for now by using an @Binds
to bind the UserComponent
binding to another interface that doesn't have the @Subcomponent
on it (e.g. @Subcomponent interface UserComponent : RealUserComponent
), and then make your val
use the interface without the @Subcomponent
.
It looks like there's a bug in our validation logic that causes this loop.
I think I follow, but if you delete SubscriberComponent
altogether, then it compiles & looking at generated sources of UserComponent, the val parent: AppComponent
does just expose the appComponentImpl
referencd which is passed in normally via constructor..so everything as expected.
I checked in the debugger, the returned instance is the same as the one used to create UserComponent instance from..so no surprises.
Is it because AppComponent
is a @Component
(and not a @Subcomponent
?)
Is it because AppComponent is a @Component (and not a @Subcomponent?)
Yea, you can't make a @Component
a child of another component, so we interpret this just as any other getter.
I see. So other than fixing the overflow to get a better error message, and hacking around with @Binds, a proper way doesnt seem feasible, since all viable syntax is already taken?
Yea, you won't be able to do exactly what you wrote in the original comment, however, we should fix the overflow. Also, I think if you did @Binds
to a qualifier like @Parent UserComponent
you'd still hit the overflow. I need to look into and discuss with team members on whether we want to allow a qualifier to be used here to make the @Binds
case easier.
by @Binds
you mean @Binds abstract fun bind(userComponent: UserComponent): RealUserComponent
?
Yup, that's right.
I want to expose parent reference of a subcomponent, since the generated implementation has the reference. (Trying to build a component cache that is a tree)
Simply adding a
val parent: AppComponent
onUserComponent
worked. But unfortunately it doesn't work for subcomponent trees deeper than 2, then compilation stackoverflows.dagger 2.51.1