Bug 84480 - Warning for "no effect assignment" j = j++
Summary: Warning for "no effect assignment" j = j++
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-02-04 16:31 EST by Timothy Halloran CLA
Modified: 2005-10-11 02:57 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 Timothy Halloran CLA 2005-02-04 16:31:52 EST
NOTE: Only applies to primitive types, i.e., int i;

Currently, Eclipse warns that "i = i;" has no effect. It would be nice to 
expand this analysis to also detect that "i = i++;" has no effect.
Comment 1 Philipe Mulet CLA 2005-02-06 08:39:02 EST
Trivial addition, and good idea.
Comment 2 Philipe Mulet CLA 2005-02-06 09:00:19 EST
Added AssignmentTest#test035.
Fixed
Comment 3 Timothy Halloran CLA 2005-02-09 16:02:44 EST
The idea is from Josh Block and Neal Gafter, sadly my only contribution is 
that it might be a good warning to add into Eclipse...Thanks!
Comment 4 Timothy Halloran CLA 2005-02-09 18:10:36 EST
I ment Josh Bloch (typo)
Comment 5 Jerome Lanneluc CLA 2005-02-15 07:47:36 EST
Verified in I20050214
Comment 6 Philipe Mulet CLA 2005-10-10 05:48:20 EDT
Actually, this is wrong. 

In "i = i++;", the assignment is not a noop. The postfix increment is. 
As a consequence, "i = i++" is equivalent to doing nothing. 
Current implementation simply removes the assignment, and leaves the postfix
increment.
Comment 7 Philipe Mulet CLA 2005-10-10 06:03:34 EDT
Also see bug 111898.

Will remove detection for this scenario. I can automate the entire deletion of
the statement, but then need to introduce a specific new problem for this case,
since the suggestion for discarding only the assignment is misleading.

b = b++;   is not equivalent to:   b++;

I do not believe this pattern is frequent enough to justify a custom problem for it.
Comment 8 Timothy Halloran CLA 2005-10-10 21:25:28 EDT
I disagree, this pattern is common enough to appear in Java Puzzlers by Bloch
and Gafter.  In addition, there is no argument that "i = i++;" is the same as
"i++;" however -- usually the latter is what the programmer wanted to do.

I've also seen it student code (undergraduate and graduate level) when students
who are fuzzy about the semantics of the ++ operator "try" it out.

It clearly is a noop -- however I do concur the light bulb should probably have
two options: (1) replace with "i++" or (2) remove the statment;
Comment 9 Philipe Mulet CLA 2005-10-11 02:57:54 EDT
Java puzzlers are not common patterns, simply weird corner cases. I agree it
would be nice to flag, but it must be flagged distinctly from an assignment with
no effect, as it does not get fixed in the same way.