Bug 302919 - misreported cast Error when mixing generic and raw class in nested class
Summary: misreported cast Error when mixing generic and raw class in nested class
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 3.6 M6   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-16 03:05 EST by CHENG Yuk Pong CLA
Modified: 2010-03-08 08:27 EST (History)
4 users (show)

See Also:
Olivier_Thomann: review+


Attachments
Patch under consideration (3.03 KB, patch)
2010-02-17 03:59 EST, Srikanth Sankaran CLA
no flags Details | Diff
Revised patch under consideration (6.79 KB, patch)
2010-02-17 07:52 EST, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description CHENG Yuk Pong CLA 2010-02-16 03:05:14 EST
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 {
	}
}
Comment 1 CHENG Yuk Pong CLA 2010-02-16 03:08:30 EST
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.
Comment 2 Srikanth Sankaran CLA 2010-02-16 04:00:58 EST
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.
Comment 3 Srikanth Sankaran CLA 2010-02-17 03:59:08 EST
Created attachment 159276 [details]
Patch under consideration
Comment 4 Srikanth Sankaran CLA 2010-02-17 07:38:04 EST
(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.
Comment 5 Srikanth Sankaran CLA 2010-02-17 07:52:39 EST
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()
Comment 6 Srikanth Sankaran CLA 2010-02-19 05:12:04 EST
Released in HEAD for 3.6M6
Comment 7 Ayushman Jain CLA 2010-03-08 07:57:54 EST
Verified for 3.6M6 using build I20100305-1011.
Comment 8 Jay Arthanareeswaran CLA 2010-03-08 08:27:11 EST
Verified.