Bug 228816 - Wrong message "assignemt has no effect" for ++ operator
Summary: Wrong message "assignemt has no effect" for ++ operator
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.4 M7   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 228817 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-04-25 00:33 EDT by Eric Bodden CLA
Modified: 2008-04-28 07:42 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Bodden CLA 2008-04-25 00:33:03 EDT
Build ID: 3.3.0

Steps To Reproduce:
See the following two little programs:
	public static void main(String[] args) {
		int i = 9;
		i = i++;
		System.out.println(i);
	}

	public static void main(String[] args) {
		int i = 9;
		i = ++i;
		System.out.println(i);
	}

In the first program the assignment has no effect because the increment only happens *after* the assignment. The program will print 9. In the second program, the assignment does have an effect, printing 10. This is all correct. However, Eclipse puts a yellow squiggle under the assignment in the second, not the first program. That's completely the wrong way around (I think).

More information:
Comment 1 Olivier Thomann CLA 2008-04-25 08:39:43 EDT
*** Bug 228817 has been marked as a duplicate of this bug. ***
Comment 2 Olivier Thomann CLA 2008-04-25 09:12:59 EDT
In fact: i = i++; has some effect as i has the same value after the assignment than before the assignment even if i was incremented. So the assignment nullifies the increment of i. So this is a side-effect of the assignment.
See bug 84480.

When writing i = ++i;, the assignment has no effect. Even if the value has changed, you don't actually need the assignment to change the value.
++i; would be enough.
See bug 100369.

The warning is about the assignment itself, not the fact that the value has changed.
Closing as INVALID.

Philippe, any further comments?
Comment 3 Eric Bodden CLA 2008-04-25 09:49:57 EDT
(In reply to comment #2)
> The warning is about the assignment itself, not the fact that the value has
> changed.
> Closing as INVALID.

Ah I guess that makes sense. Sorry. Mea culpa.
Comment 4 Jerome Lanneluc CLA 2008-04-28 07:42:42 EDT
Was verified for 3.4M7 by reporter (comment 3)