Summary: | Warning for "no effect assignment" j = j++ | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Timothy Halloran <hallorant> |
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> |
Status: | VERIFIED FIXED | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | ||
Version: | 3.1 | ||
Target Milestone: | 3.1 M5 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
Timothy Halloran
2005-02-04 16:31:52 EST
Trivial addition, and good idea. Added AssignmentTest#test035. Fixed 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! I ment Josh Bloch (typo) Verified in I20050214 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. 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. 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; 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. |