| Summary: | [1.5][compiler] Compiler Type Inference Inconsistency with Sun javac | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Daniel Spiewak <djspiewak> | ||||
| Component: | Core | Assignee: | Srikanth Sankaran <srikanth_sankaran> | ||||
| Status: | CLOSED WONTFIX | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | kent_johnson, Olivier_Thomann, srikanth_sankaran | ||||
| Version: | 3.4 | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows Vista | ||||||
| Whiteboard: | stalebug | ||||||
| Attachments: |
|
||||||
|
Description
Daniel Spiewak
My appologies, the line is net.java.ao.EntityManager:466 in the broken version. Please try to reduce the case. What is the error from javac? I have managed to reduce the case. I'm zipping up and attaching a full Eclipse JDT project which reproduces (basically 5 stub classes). The error I get with javac is as follows: C: Created attachment 79572 [details]
CompilerBrokenExample Project
Seems Mylyn screwed up that trace. Trying again...
C:\Users\Daniel Spiewak\Development\workspace\CompilerBrokenCase\src>javac -target 1.5 *.java
Driver.java:13: inconvertible types
found : java.lang.Class<capture#935 of ? extends TestInterface<capture#262 of ?>>
required: java.lang.Class<TestInterface<?>>
target.get((Class<TestInterface<?>>) value.getType()).put(value);
^
1 error
We're reporting an unchecked cast warning, but javac is reporting an error.
Reduced the case a bit more:
class X {
<T> C<T> get(Class<T> clazz) { return null; }
void test(I<?> value) {
get((Class<I<?>>) value.getType()).put(value); // javac ERROR
}
}
abstract class C<T> {
abstract void put(T value);
}
interface I<T> {
Class<? extends I<T>> getType();
}
---------------------
X.java:4: inconvertible types
found : java.lang.Class<capture of ? extends I<capture of ?>>
required: java.lang.Class<I<?>>
get((Class<I<?>>) value.getType()).put(value);
Even more reduced scenario:
public class X {
void test(I<?> value) {
Class<I<?>> cl = (Class<I<?>>) value.getType();
}
}
interface I<T> {
Class<? extends I<T>> getType();
}
Basically, the problem resides in the definition of provable distinctness of types, which is underspecified today. There are discussions in progress to make the spec stricter. Javac is already stricter, but also has bugs in this area (sometimes too strict than it needs to be).
I believe this is a Javac bug, and even once we make the cast rules a bit stricter to eliminate obvious incompatible types, this example should still compile clean with a warning.
Also see related issues: bug 158870, bug 90433, bug 89940, bug 90437 ...
My current work in progress for making Eclipse compiler stricter is still accepting this scenario as valid (with unchecked cast warning).
It actually makes a lot of sense that this is a bug with javac. Logically, the type inference is sound. Also, there are similar syntaxes allowed by javac under different situations. Should this be opened in a bug against the JDK? I believe so. Note that the javac bug database has a couple entries for cast issues... so you may be able to find existing entries. Our cast rules still differ from javac 7
We report the same error for the 2nd & 3rd, but only a warning for the 1st
class X {
void test(I<?> value) {
// found : Class<capture#918 of ? extends I<capture#289 of ?>>
// required: Class<I<?>>
Object o = (Class<I<?>>) value.getType();
// found : Class<capture#867 of ? extends I<capture#651 of ?>>
// required: Class<I<?>>
Class<I<?>> c = value.getType();
}
Class<I<?>> test2(I<?> value) {
// found : Class<capture#114 of ? extends I<capture#556 of ?>>
// required: Class<I<?>>
return value.getType();
}
}
interface I<T> {
Class<? extends I<T>> getType();
}
Another cast related bug 170064 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. |