-
-
Notifications
You must be signed in to change notification settings - Fork 65
CodeGeneration ver 0.7.2 to ver 0.8.0 #487
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
Comments
Thanks for the report, if you can share a component graph that reproduces the issue that'd help a lot |
sure here is graph classes
code screenshots I did share code generated for |
From what I could see in new code generation is that tries to bind provided component dependencies from itself as it seems it looks for them with |
If you still need a graph, here's a simple one: @Inject
class Repository(val http: Http)
@Inject
class RealHttp : Http
interface Http
@Component
abstract class AppComponent {
@Provides
fun provideRealHttp(): RealHttp = RealHttp()
val RealHttp.bind: Http
@Provides get() = this
}
@Component
abstract class ActivityComponent(
@Component val appComponent: AppComponent,
) {
abstract val repo: Repository
} results in
public fun KClass<ActivityComponent>.create(appComponent: AppComponent): ActivityComponent = InjectActivityComponent(appComponent)
public class InjectActivityComponent(
appComponent: AppComponent,
) : ActivityComponent(appComponent) {
override val repo: Repository
get() = Repository(
http = with(appComponent) {
this@InjectActivityComponent.provideRealHttp().bind
}
)
} |
Looks like it has to do with the combination of receivers and parent bindings. In the meantime switching from a receiver to a function arg should work around it. @Provides fun bindHttp(real: RealHttp): Http = real instead of val RealHttp.bind: Http
@Provides get() = this |
I've merged in a fix, can you test by pointing to the snapshot version and see if it resolves this issue? repositories {
maven {
uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
}
dependencies {
ksp("me.tatarka.inject:kotlin-inject-compiler-ksp:0.8.1-SNAPSHOT")
} |
@evant It works on my end, thanks! |
Seems like we can trigger a variation of the bug when using Repro @Inject
class Repository(val http: Http, @Assisted val url: String) {
@AssistedFactory
fun interface Factory {
operator fun invoke(url: String): Repository
}
}
@Inject class RealHttp : Http
interface Http
@Component
abstract class AppComponent {
abstract val repoFactory: Repository.Factory
@Provides fun provideRealHttp(): RealHttp = RealHttp()
val RealHttp.bind: Http
@Provides get() = this
} Generated code public fun KClass<AppComponent>.create(): AppComponent = InjectAppComponent()
public class InjectAppComponent : AppComponent() {
override val repoFactory: Repository.Factory
get() = object : Repository.Factory {
override fun invoke(url: String): Repository = Repository(
http = this@InjectAppComponent.this@InjectAppComponent.provideRealHttp().bind,
url = url
)
}
} |
We'd get foo = [email protected]@InjectAssistedFactoryComponent.provideFoo().bind instead of foo = [email protected]().bind See evant#487 (comment)
We'd get foo = [email protected]@InjectAssistedFactoryComponent.provideFoo().bind instead of foo = [email protected]().bind See evant#487 (comment)
We'd get foo = [email protected]@InjectAssistedFactoryComponent.provideFoo().bind instead of foo = [email protected]().bind See #487 (comment)
code generation produce invalid dependency access in newer version you could see in the screen shots.
The text was updated successfully, but these errors were encountered: