| Summary: | [1.5] Compiler rejects valid assignment involving generics | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | John Kozlov <orionllmain> |
| Component: | Core | Assignee: | Stephan Herrmann <stephan.herrmann> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | jarthana, lukas.eder, stephan.herrmann |
| Version: | 4.3 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | |||
This is not a regression, the issue can be reproduced all the way back to ecj 3.2.2. (In reply to comment #0) > This code should compile, because the identical code compiles in Eclipse: This is not a hard proof. Since Collections.singleton is a generic method the compiler needs to apply type inference to find the correct instantiation. If inference fails, it shouldn't surprise that making the intermediate type explicit helps the compiler to recognize the program as type safe. The statement in bug 425203 comment 1 also holds for this bug. I'm looking through Eclipse bugs similar to this one. This one here, I can no longer reproduce with 4.5.0M3. Perhaps a duplicate? (In reply to Lukas Eder from comment #3) > I'm looking through Eclipse bugs similar to this one. This one here, I can > no longer reproduce with 4.5.0M3. Perhaps a duplicate? Thanks for retesting. In current HEAD I see: - accept at -1.8 - reject at -1.7 with this error (same as comment 0): 1. ERROR in /tmp/Test.java (at line 4) Set<T> set = Collections.singleton(list.get(0)); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Type mismatch: cannot convert from Set<capture#1-of ? extends T> to Set<T> ---------- 1 problem (1 error) This means we're not likely to find a duplicate, as the change in behavior is just a result of entirely new type inference (spec & impl) in Java 8. OTOH, at 1.7 and below we still deviate from javac behavior, but I personally wouldn't give a high priority to fixing this, considering also that in JLS7 (i.e., without target typing) our behaviour could well be the correct one. (The "identical code" in comment 0 is *not* identical from a type inference p.o.v). I see, yes I've only tested this with Java 8 This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. I don't plan to fix the legacy modes 1.7 or below. |
The following code compiles with Java 6 compiler, but fails in Eclipse: public static <T> void f(List<? extends T> list) { Set<T> set = Collections.singleton(list.get(0)); } The error is: "Type mismatch: cannot convert from Set<capture#1-of ? extends T> to Set<T> (Java Problem)" This code should compile, because the identical code compiles in Eclipse: public static <T> void f(List<? extends T> list) { T t = list.get(0); Set<T> set = Collections.singleton(t); }