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

Scoped generic class fails to build #671

Closed
bubenheimer opened this issue Mar 29, 2017 · 2 comments
Closed

Scoped generic class fails to build #671

bubenheimer opened this issue Mar 29, 2017 · 2 comments
Assignees

Comments

@bubenheimer
Copy link

bubenheimer commented Mar 29, 2017

The following fails to build:

@Component
interface FooComp {
    Foo<Integer> foo();
}

@Reusable
class Foo<T> {
    @Inject
    Foo() {}
}

Error:(26, 44) error: incompatible types: Provider<Foo<Object>> cannot be converted to Provider<Foo<Integer>>

However, when adding another @Inject element or removing scoping it succeeds:

@Reusable
class Foo<T> {
    @Inject
    Foo() {}

    @Inject
    void postConstruct() {}
}

The problem in the first case is that Dagger is overeager to use a single static factory instance for generating instances of scoped generic classes.

@bubenheimer bubenheimer changed the title @Reusable generic class fails to build Scoped generic class fails to build Mar 29, 2017
@bubenheimer
Copy link
Author

I guess all that's really missing in the generated code is a typecast to Provider to achieve erasure bliss. Didn't spot it right away.

@bubenheimer
Copy link
Author

The issue does not occur with -source 1.8. It does with -source 1.7.

ronshapiro pushed a commit that referenced this issue Apr 25, 2017
…scoping generic @Inject classes.

Fixes #671

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=154187714
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

No branches or pull requests

2 participants