Bug 40572 - Unnecessary cast warning for necessary cast
Summary: Unnecessary cast warning for necessary cast
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-21 17:56 EDT by John Arthorne CLA
Modified: 2003-08-28 04:51 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Arthorne CLA 2003-07-21 17:56:43 EDT
Build: 3.0 M2

Given the following three compilation units:

package p1;
public class A {
	void foo() {
	}
}
---
package p2;
import p1.A;
public class B extends A {
}
---
package p1;
import p2.B;
public class C {
	public void bar() {
		B b = new B();
		((A)b).foo();//warning for necessary cast
	}
}

The new warning for unnecessary casts reports a warning in C on the commented
line.  If the cast is removed, a compile error results (due to visibility
restriction), therefore this cast IS necessary.
Comment 1 Philipe Mulet CLA 2003-07-22 04:51:50 EDT
Did not consider alternate receiver type, only argument types. 
Comment 2 Philipe Mulet CLA 2003-07-22 05:08:17 EDT
Fixed. Added regression test (NegativeTest#test395)
Comment 3 Philipe Mulet CLA 2003-07-22 07:35:18 EDT
Access to member types also had a similar defficiency (replace (A)b.foo() with 
(A)b.new Member(), with A defining member type.
Comment 4 David Audel CLA 2003-08-28 04:51:09 EDT
Verified.