Community
Participate
Working Groups
The following code compiles normally in JDK 1.5.0_06, but fails in Eclipse 3.2RC3 (build id I20060505-1306), with a "T.Inner cannot be resolved to a type" error located at the line marked with a //** comment. package p1; public class Outer { public class Inner { } } class ATest<T extends Outer> { public ATest() { T instance = makeInstance(); Outer.Inner peq = instance.new Inner(); //** } private T makeInstance() { return (T) new Outer(); } }
Javac 1.6 agrees with us: Outer.java:10: cannot select from a type variable Outer.Inner peq = instance.new Inner(); //** ^ Outer.java:14: warning: [unchecked] unchecked cast found : Outer required: T return (T) new Outer(); ^ 1 error 1 warning
(In reply to comment #1) So, this means that the bug likely is in Javac 5? I tried looking it up in the the Java lang spec, but it's a bit over my head...
Yes, this would be a javac bug in 1.5. Added GenericTypeTest#test0993
Our error message may be slightly improved, along the line of bug 128423
I am not seeing either any argument against it in the spec. In 4.4, it claims: "The members of a type variable X with bound T & I1 ... In are the members of the intersection type (§4.9) T & I1 ... In appearing at the point where the type variable is declared." Then in 4.9, last bullet: "• Then the intersection type has the same members as a class type (§8) with an empty body, direct superclass Ck and direct superinterfaces IT1 , ..., ITn, declared in the same package in which the intersection type appears."
Added GenericTypeTest#test0994
Member types should be reachable through type variables, and got disallowed when addressing bug 128423 (3.2RC1).
Also added GenericTypeTest#test0997
Created attachment 42869 [details] Patch for the tests
Created attachment 42870 [details] Proposed patch Patch is re-enabling finding member types through type variables, also needs to tackle reentering connect type hierarchies algorithm.
Released GenericTypeTest, with new tests disabled: test0229 - expectation should change, new behavior guarded by "if (false)" test0306 - expectation should change, new behavior guarded by "if (false)" _test0917a - to be enabled _test0993 - to be enabled _test0994 - to be enabled _test0995 - to be enabled _test0997 - to be enabled
I think case 917 & 917a should report that you cannot access anything from the type variable while connecting its class' hierarchy. In 1.5, case 917 currently causes a walkback and in 1.6, it reports that you cannot select from a type variable. Philippe, are you sure these cases should be changed?
Ok to not resolve them in type hierarchies. Note that javac confessed bugs in this area, will see how things evolve in the future.
Released new fix and enabled Generic type tests
Released for 3.2.1 Released for 3.3 M1 while merging TARGET_321 in HEAD
Verified for 3.3 M1 using build I20060807-0010.
Verified for 3.2.1 using build M20060908-1655.
*** Bug 241710 has been marked as a duplicate of this bug. ***