-
Notifications
You must be signed in to change notification settings - Fork 2k
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
2.12: Eclipse compilation errors #949
Comments
Reported bug to Eclipse: https://bugs.eclipse.org/bugs/show_bug.cgi?id=527238 |
There may or may not be a bug in the Eclipse compiler. Unfortunately, just answering this question requires significant efforts in each individual case (the specification is sufficiently complex, and comparison against javac is not reliable, either). IMHO, development effort is much better invested in developing and polishing new language features, rather than trying to repair, what was intended only as a short-term, interim workaround for migration of Java 1.4 code. Raw types are a broken concept in Java 8+, and should be removed from the language as it was announced right from the beginning. For those reasons I beg the dagger developers, to avoid raw types in generated code (and thus avoid the impression you are generating code for the year 2003 or earlier ;p ). |
Raw types are unfortunately necessary in some cases - consider when you have a package-private binding in package
I don't know what you're referring to. |
I know close to nothing about dagger, but this sounds like a strange design to me. If visibility prohibits the use of generics then the problem must be solved at the level of visibility, not by relying on tricks to avoid mentioning the inaccessible type. I don't have sufficient background to judge the importance of supporting package-private bindings that need to be accessed outside the package, though.
Regarding "broken": raw types defeat the improved type inference in Java 8 (and obviously raw types imply that "type-correct" code can throw type errors at runtime, which is totally against the spirit of a statically typed language like Java). Regarding removal, see JLS §4.8: "The use of raw types is allowed only as a concession to compatibility of legacy code. The use of raw types in code written after the introduction of generics into the Java programming language is strongly discouraged. It is possible that future versions of the Java programming language will disallow the use of raw types." |
The simple case is something like this: pkg a;
class Foo {
@Inject Foo(Set<Object> multiboundObjects) {}
@Override public String toString() { return multiboundObjects.toString() + getClass().getName(); }
} pkg a;
public class Bar {
@Inject Bar(Provider<Foo> dependencyOnFoo) {}
public void doStuff() {
System.out.println(dependencyOnFoo.get().toString());
}
}
You're right that using raw types is not ideal, but we don't have much of a choice. I would be very surprised if that statement in the JLS was actually enacted - if for nothing else, it supports things like |
What's wrong with To be fair, there is one case where raw types are unavoidable, unfortunately: class literals of generic classes. |
To get back on track: we only test with We're not inclined to start including extra casts all over the place to support a compiler that we can't easily test, and we especially don't want multiple compilation modes. In the past we've seen other issues with ECJ and given that It's possible that we could start using wildcards everywhere, but that would be an enormous undertaking that we don't have time for, nor is it clear that it will in fact work. Another workaround is making your types public - it's obviously not ideal but if you put a comment it should allow you to move on. |
@ronshapiro it is not a problem of publicity (it is not a workaround), it is another problem: The better fix is to make Factory method |
@ronshapiro will you accept pull-request with fixing Factory::create method interface with replacing Provider to Provider<? extends A>? |
You're welcome to try. I imagine it will be more difficult than you perceive, but I'm happy to review it if you can get it working. |
FYI, this is the bug in JDT related to the situation above. |
Updated https://bugs.eclipse.org/bugs/show_bug.cgi?id=513567 to include the workaround proposed in PR #957. @stephan-herrmann, could you comment if you see any problem with this workaround? |
… satisfy Java 9 Eclipse JDT type inference quirks Fixes #949 Closes #957 RELNOTES=Fixed a compilation issue with eclipse ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178773557
… satisfy Java 9 Eclipse JDT type inference quirks Fixes #949 Closes #957 RELNOTES=Fixed a compilation issue with eclipse ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178773557
Hello, this bug is the same as #896
Actually, it is not a bug of dagger, but of eclipse.
Another bug of eclipse, that can be reproduced with dagger codegen (#380) was reported to eclipse (https://bugs.eclipse.org/bugs/show_bug.cgi?id=513567) but it was not fixed for 8 months. This bug can be simply avoided.
The reported bug can not be simply fixed without fixing generated code. (or changing @BINDS to @provides, but it is not a right way)
I think, it will be right to change dagger codegen of Component - it should always cast Factory to Provider like this:
this.someProvider = DoubleCheck.provider((Provider)Some_Factory.create((Provider) dependency));
instead of this:
this.someProvider = DoubleCheck.provider(Some_Factory.create((Provider) dependency));
All Eclipse users will say thank you :)
The text was updated successfully, but these errors were encountered: