Bug 185787 - [1.5][compiler] Missing unnecessary cast diagnosis
Summary: [1.5][compiler] Missing unnecessary cast diagnosis
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 RC1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-07 11:24 EDT by Philipe Mulet CLA
Modified: 2007-05-15 10:07 EDT (History)
1 user (show)

See Also:
Olivier_Thomann: review+


Attachments
Proposed patch (5.84 KB, patch)
2007-05-07 12:46 EDT, Philipe Mulet CLA
no flags Details | Diff
Same patch + new regression tests and other tests cleanup (11.45 KB, patch)
2007-05-07 14:01 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2007-05-07 11:24:31 EDT
3.3M7

The following code could report an unnecessary cast.

import java.awt.Container;
import java.util.Collection;
public class X {
	private <T extends Container> Collection<T> foo() {
		return null;
	}

	private void showProblem() {
		Collection<?> result = (Collection<Container>)foo(); // unnecessary cast
	}
}
Comment 1 Philipe Mulet CLA 2007-05-07 12:45:21 EDT
Problem comes from the fact the MethodBinding.inferredReturnType is incorrectly set when there is no explicit expected type (as in this case, where Cast context is not providing any - as per JLS), and a default one is supplied (Object).

Need to record a flag indicating this fact. Stored the data on inferenceContext directly, instead of passing it around as an argument.
Comment 2 Philipe Mulet CLA 2007-05-07 12:46:21 EDT
Created attachment 66146 [details]
Proposed patch
Comment 3 Philipe Mulet CLA 2007-05-07 12:47:08 EDT
Olivier - pls review
Comment 4 Olivier Thomann CLA 2007-05-07 13:06:55 EDT
I could not apply the patch for the regression tests.
The patch could be successfully applied for the changes in the org.eclipse.jdt.core project.
I'll review the changes in org.eclipse.jdt.core for now.
Could you please resubmit the patch for the regression tests' update?
Thanks.
Comment 5 Olivier Thomann CLA 2007-05-07 13:10:56 EDT
I didn't get the latest version of GenericTypeTest before applying the patch. The patch can be applied successfully now.
Comment 6 Olivier Thomann CLA 2007-05-07 13:59:56 EDT
Patch looks good.
I'll update the patch with a new regression test for the test case below.
Comment 7 Olivier Thomann CLA 2007-05-07 14:01:24 EDT
Created attachment 66164 [details]
Same patch + new regression tests and other tests cleanup
Comment 8 Philipe Mulet CLA 2007-05-07 16:18:26 EDT
Released for 3.3RC1.
Fixed
Comment 9 Philipe Mulet CLA 2007-05-07 17:08:04 EDT
Regression test was comprised in GenericTypeTest#test1137 already (just some tweaking for extra warning... basically this is how I noticed this very bug).

Please apply your other cleanup in the tests.
Comment 10 Eric Jodet CLA 2007-05-15 07:55:46 EDT
Verified for 3.3 RC1 using I20070515-0010