Summary: | [compiler] Unnecessary cast warning for cast from char to int | ||||||||
---|---|---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Gunter Herrmann <gunter_herrmann> | ||||||
Component: | Core | Assignee: | Kent Johnson <kent_johnson> | ||||||
Status: | VERIFIED FIXED | QA Contact: | |||||||
Severity: | normal | ||||||||
Priority: | P3 | CC: | Olivier_Thomann, srikanth_sankaran | ||||||
Version: | 3.5 | ||||||||
Target Milestone: | 3.6 M1 | ||||||||
Hardware: | PC | ||||||||
OS: | Windows XP | ||||||||
Whiteboard: | |||||||||
Attachments: |
|
Description
Gunter Herrmann
2009-07-08 11:02:26 EDT
I could not reproduce this with the supplied code after setting 'unnecessary cast' to a warning. Please attach a complete test project, with jdt.core.prefs file (In reply to comment #0) > Build ID: 20090621-0832 > > Steps To Reproduce: > 1. Use code below > 2. See different results > > > > More information: > char a = 65; > String b = "" + a; // -> "A" > String c = "" + (int) a; // -> "65", shows unnecessary cast > Sorry I oversimplified the problem. Now here the code that really did it: String logText = "Some message "; char firstChar = 65; // really getting something from a TCP/IP connection logText += (int) firstChar; Created attachment 141671 [details]
Proposed fix
Kent, please review.
The support was already there for binary expression. Therefore this is why the first test case in comment 0 didn't reproduce the problem. The CompoundAssignment didn't get a specific treatment for unnecessary cast detection. I'll release a disabled regression test in the CastTest. Added and released disabled test: org.eclipse.jdt.core.tests.compiler.regression.CastTest#_test046 Created attachment 142290 [details]
Proposed patch and testcase
Released in HEAD for 3.6M1 Verified for 3.6M1 using build I20090802-2000 |