Bug 44400 - Unnecessary cast not being picked up
Summary: Unnecessary cast not being picked up
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-08 05:28 EDT by Thomas M??der CLA
Modified: 2003-11-19 10:00 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas M??der CLA 2003-10-08 05:28:41 EDT
I2003-10-07

consider the following class: 

public class Balk {
	public void foo(Object bar) {
		System.out.println(((Object)bar).toString());
	}
}


Clearly, the cast to Object in the println is unnecessary. This is not flagged
by the compiler, even though the "unnecessary cast or instanceof" is selected on
the preference page (either warning or error).
Comment 1 Olivier Thomann CLA 2003-10-08 08:28:42 EDT
It seems that we tag the cast expression to check the unnecessary cast later using:
if (this.receiver instanceof CastExpression) this.receiver.bits |=
IgnoreNeedForCastCheckMASK; // will check later on

in the MessageSend type resolution (toString() call).
Then inside the cast expression, we detect the unnecessary cast, but we don't
report it.
Comment 2 Philipe Mulet CLA 2003-10-09 17:45:32 EDT
Problem occurs as well for field references.
Comment 3 Philipe Mulet CLA 2003-10-09 18:26:48 EDT
Added regression tests:

CastTest#test024
CastTest#test025

Fixed. Will be released publicly once M4 is declared
Comment 4 David Audel CLA 2003-11-19 10:00:51 EST
Verified