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

Generated member injectors for parameterized classes don't compile #29

Closed
arctouch-ianribas opened this issue Jul 29, 2024 · 0 comments · Fixed by #30
Closed

Generated member injectors for parameterized classes don't compile #29

arctouch-ianribas opened this issue Jul 29, 2024 · 0 comments · Fixed by #30

Comments

@arctouch-ianribas
Copy link
Contributor

Generated member injectors for parameterized classes don't compile. The current implementation generates invalid kotlin code, missing a reference to the parameterized types. This fails for both kotlin and java parameterized classes.

Generating member injector for classes such as:

    class TestFieldInjection<T> {
        @Inject lateinit var foo: Foo
    }

Results in:

    public class TestFieldInjection__MemberInjector : MemberInjector<TestFieldInjection> {
        public override fun inject(target: TestFieldInjection, scope: Scope): Unit {
            target.foo = scope.getInstance(Foo::class.java) as Foo
        }
    }

Which fails compilation with errors like:

e: file:/path/to/TestFieldInjection:106:65 One type argument expected for class TestFieldInjection<T>

For most cases, the injected dependencies are independent of the parameterized type, so the member injectors can be build using the general * as the type. For the example above, that would give:

    public class TestFieldInjection__MemberInjector : MemberInjector<TestFieldInjection<*>> {
        public override fun inject(target: TestFieldInjection<*>, scope: Scope): Unit {
            target.foo = scope.getInstance(Foo::class.java) as Foo
        }
    }
arctouch-ianribas added a commit to arctouch-ianribas/toothpick-ksp that referenced this issue Jul 29, 2024
Generate correct member injectors for parameterized classes using the general star (`*`) for all type arguments of the target class.

Member injectors for non generic/parameterized classes works as before.

Fixes BedrockStreaming#29.
arctouch-ianribas added a commit to arctouch-ianribas/toothpick-ksp that referenced this issue Aug 21, 2024
Generate correct member injectors for parameterized classes using the general star (`*`) for all type arguments of the target class.

Member injectors for non generic/parameterized classes works as before.

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

Successfully merging a pull request may close this issue.

1 participant