### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java,v retrieving revision 1.117 diff -u -r1.117 SingleNameReference.java --- compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 7 Apr 2010 12:47:50 -0000 1.117 +++ compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 1 Jul 2010 21:07:23 -0000 @@ -77,9 +77,7 @@ currentScope.problemReporter().uninitializedLocalVariable(localBinding, this); // we could improve error msg here telling "cannot use compound assignment on final local variable" } - if (isReachable) { - localBinding.useFlag = LocalVariableBinding.USED; - } else if (localBinding.useFlag == LocalVariableBinding.UNUSED) { + if (localBinding.useFlag == LocalVariableBinding.UNUSED) { localBinding.useFlag = LocalVariableBinding.FAKE_USED; } } @@ -461,6 +459,14 @@ * are optimized in one access: e.g "a = a + 1" optimized into "a++". */ public void generateCompoundAssignment(BlockScope currentScope, CodeStream codeStream, Expression expression, int operator, int assignmentImplicitConversion, boolean valueRequired) { + if (!valueRequired && ((this.bits & ASTNode.RestrictiveFlagMASK) == Binding.LOCAL)) { + LocalVariableBinding localBinding = (LocalVariableBinding) this.binding; + if (localBinding.useFlag == LocalVariableBinding.FAKE_USED) { + // report the case of a local variable that is unread except for this compound assignment + currentScope.problemReporter().unusedLocalVariable(localBinding.declaration); + localBinding.useFlag = LocalVariableBinding.USED; // don't report again + } + } this.generateCompoundAssignment( currentScope, codeStream, @@ -661,6 +667,15 @@ return; case Binding.LOCAL : // assigning to a local variable LocalVariableBinding localBinding = (LocalVariableBinding) this.binding; + + if (!valueRequired) { + if (localBinding.useFlag == LocalVariableBinding.FAKE_USED) { + // report the case of a local variable that is unread except for postIncrement expressions + currentScope.problemReporter().unusedLocalVariable(localBinding.declaration); + localBinding.useFlag = LocalVariableBinding.USED; // don't report again + } + } + // using incr bytecode if possible if (localBinding.type == TypeBinding.INT) { if (valueRequired) {