View | Details | Raw Unified | Return to bug 310264 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java (-1 / +1 lines)
Lines 160-166 Link Here
160
	}
160
	}
161
	// check for assignment with no effect
161
	// check for assignment with no effect
162
	Binding left = getDirectBinding(this.lhs);
162
	Binding left = getDirectBinding(this.lhs);
163
	if (left != null && left == getDirectBinding(this.expression)) {
163
	if (left != null && !left.isVolatile() && left == getDirectBinding(this.expression)) {
164
		scope.problemReporter().assignmentHasNoEffect(this, left.shortReadableName());
164
		scope.problemReporter().assignmentHasNoEffect(this, left.shortReadableName());
165
	}
165
	}
166
166
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Binding.java (+3 lines)
Lines 91-96 Link Here
91
	public final boolean isValidBinding() {
91
	public final boolean isValidBinding() {
92
		return problemId() == ProblemReasons.NoError;
92
		return problemId() == ProblemReasons.NoError;
93
	}
93
	}
94
	public boolean isVolatile() {
95
		return false;
96
	}
94
	/* API
97
	/* API
95
	* Answer the problem id associated with the receiver.
98
	* Answer the problem id associated with the receiver.
96
	* NoError if the receiver is a valid binding.
99
	* NoError if the receiver is a valid binding.
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java (+45 lines)
Lines 1638-1641 Link Here
1638
		"a cannot be resolved to a variable\n" + 
1638
		"a cannot be resolved to a variable\n" + 
1639
		"----------\n");
1639
		"----------\n");
1640
}
1640
}
1641
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=310264
1642
public void test0044() {
1643
	this.runNegativeTest(
1644
		new String[] {
1645
			"X.java",
1646
			"class X {\n" + 
1647
			"   volatile int x;\n" +
1648
			"   int nvx;\n" +
1649
			"	void foo(int i) {\n" +
1650
			"		x = x;\n" + 
1651
			"       nvx = nvx;\n" +
1652
			"	}\n" + 
1653
			"}"
1654
		},
1655
		"----------\n" + 
1656
		"1. WARNING in X.java (at line 6)\n" + 
1657
		"	nvx = nvx;\n" + 
1658
		"	^^^^^^^^^\n" + 
1659
		"The assignment to variable nvx has no effect\n" + 
1660
		"----------\n");
1661
}
1662
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=310264
1663
public void test0045() {
1664
	this.runNegativeTest(
1665
		new String[] {
1666
			"X.java",
1667
			"class X {\n" + 
1668
			"   volatile int x = this.x;\n" +
1669
			"   int nvx = this.nvx;\n" +
1670
			"	void foo(int i) {\n" +
1671
			"	}\n" + 
1672
			"}"
1673
		},
1674
		"----------\n" + 
1675
		"1. WARNING in X.java (at line 2)\n" + 
1676
		"	volatile int x = this.x;\n" + 
1677
		"	             ^^^^^^^^^^\n" + 
1678
		"The assignment to variable x has no effect\n" + 
1679
		"----------\n" + 
1680
		"2. WARNING in X.java (at line 3)\n" + 
1681
		"	int nvx = this.nvx;\n" + 
1682
		"	    ^^^^^^^^^^^^^^\n" + 
1683
		"The assignment to variable nvx has no effect\n" + 
1684
		"----------\n");
1685
}
1641
}
1686
}

Return to bug 310264