Community
Participate
Working Groups
Build Identifier: I20100129-1300 The following example have different behavior from Sun javac 1.5.0_22 In eclipse, only m1() give error: Cannot cast from D<T>.D1 to A.A1 A.java /V/src line 7 In Sun javac, only m2() give error: A.java:11: ')' expected A.A1 v = ((A<T>.A1) tree.root); ^ A.java:11: illegal start of expression A.A1 v = ((A<T>.A1) tree.root); ^ 2 errors Reproducible: Always Steps to Reproduce: public class A<T> extends D<T> { public class A1 extends D1 { } void m1(A<T> tree) { A.A1 v = ((A.A1) tree.root); } void m2(A<T> tree) { A.A1 v = ((A<T>.A1) tree.root); } } class D<T> { protected D1 root; protected class D1 { } }
Note, if I change 3: public class A1 extends D1 { into 3: public class A1 extends D.D1 { eclipse give no error, while javac give the same error.
See that m2() compiles fine with javac7 (b77) This is due most likely to the fact that the cluster of bugs in javac in this area http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6481655 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6665356 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6795580 are all delivered only on JDK7 stream. The case with m1() is under investigation.
Created attachment 159276 [details] Patch under consideration
(In reply to comment #3) > Created an attachment (id=159276) [details] > Patch under consideration (1) This patch "fails" the following tests: org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test1336() org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test1337() Basically in the following program: public class X { void foo(Other2<?>.Member2<?> om2) { Other<String>.Member m = (Other<String>.Member) om2; } } class Other<T> { class Member {} } class Other2<T> extends Other<T> { class Member2<U> extends Other<U>.Member { } } the line: Other<String>.Member m = (Other<String>.Member) om2; gets tagged with an error message: "Cannot cast from Other2<?>.Member2<capture#1-of ?> to Other<String>.Member" I think this cast is valid - it is also accepted by javac7. So it would appear that these tests are encoded incorrectly and need to be remastered. (2) Another interesting experiment: public class C { void foo(Other2<?>.Member2<?> om2) { Other<?>.Member m = (Other<?>.Member) om2; m = om2; } } class Other<T> { class Member {} } class Other2<T> extends Other<T> { class Member2<U> extends Other<U>.Member { } } In this program, the assignment with the cast (needless) fails to compile, while the effectively equivalent assignment compiles fine. Both compile fine with javac7.
Created attachment 159297 [details] Revised patch under consideration New tests added via: org.eclipse.jdt.core.tests.compiler.regression.CastTest.test048() org.eclipse.jdt.core.tests.compiler.regression.CastTest.test049() org.eclipse.jdt.core.tests.compiler.regression.CastTest.test050() Existing tests remastered: org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test1336() org.eclipse.jdt.core.tests.compiler.regression.GenericTypeTest.test1337()
Released in HEAD for 3.6M6
Verified for 3.6M6 using build I20100305-1011.
Verified.