### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java,v retrieving revision 1.370 diff -u -r1.370 Scope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 1 Jul 2010 04:39:19 -0000 1.370 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 5 Jul 2010 11:21:51 -0000 @@ -1688,7 +1688,9 @@ } if (foundField.isValidBinding()) // if a valid field was found, complain when another is found in an 'immediate' enclosing type (that is, not inherited) - if (foundField.declaringClass != fieldBinding.declaringClass) + // but only if "valid field" was inherited in the first place. + if (foundField.declaringClass != fieldBinding.declaringClass && + foundField.declaringClass != foundActualReceiverType) // https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956 // i.e. have we found the same field - do not trust field identity yet return new ProblemFieldBinding( foundField, // closest match #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java,v retrieving revision 1.84 diff -u -r1.84 LookupTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 23 Jun 2010 06:52:41 -0000 1.84 +++ src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 5 Jul 2010 11:21:55 -0000 @@ -3176,6 +3176,153 @@ "The type B$A is not visible\n" + "----------\n"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956 +public void test098() { + Map options = getCompilerOptions(); + CompilerOptions compOptions = new CompilerOptions(options); + if (compOptions.complianceLevel < ClassFileConstants.JDK1_4) return; + this.runNegativeTest( + new String[] { + "A.java",//------------------------------ + "public class A {\n" + + " private int x;\n" + + " static class B {\n" + + " private int x;\n" + + " private C c = new C() {\n" + + " void foo() {\n" + + " x = 3;\n" + + " }\n" + + " };\n" + + " }\n" + + " static class C {\n" + + " private int x;\n" + + " }\n" + + " }\n", + }, + "----------\n" + + "1. WARNING in A.java (at line 2)\n" + + " private int x;\n" + + " ^\n" + + "The field A.x is never read locally\n" + + "----------\n" + + "2. WARNING in A.java (at line 4)\n" + + " private int x;\n" + + " ^\n" + + "The field A.B.x is never read locally\n" + + "----------\n" + + "3. WARNING in A.java (at line 5)\n" + + " private C c = new C() {\n" + + " ^\n" + + "The field A.B.c is never read locally\n" + + "----------\n" + + "4. WARNING in A.java (at line 6)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type new A.C(){} is never used locally\n" + + "----------\n" + + "5. WARNING in A.java (at line 7)\n" + + " x = 3;\n" + + " ^\n" + + "Write access to enclosing field A.B.x is emulated by a synthetic accessor method\n" + + "----------\n" + + "6. WARNING in A.java (at line 12)\n" + + " private int x;\n" + + " ^\n" + + "The field A.C.x is never read locally\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956 +public void test099() { + Map options = getCompilerOptions(); + CompilerOptions compOptions = new CompilerOptions(options); + if (compOptions.complianceLevel < ClassFileConstants.JDK1_4) return; + this.runNegativeTest( + new String[] { + "A.java",//------------------------------ + "public class A {\n" + + " private int x;\n" + + " static class B {\n" + + " private int x;\n" + + " private C c = new C() {\n" + + " void foo() {\n" + + " x = 3;\n" + + " }\n" + + " };\n" + + " }\n" + + " static class C {\n" + + " public int x;\n" + + " }\n" + + " }\n", + }, + "----------\n" + + "1. WARNING in A.java (at line 2)\n" + + " private int x;\n" + + " ^\n" + + "The field A.x is never read locally\n" + + "----------\n" + + "2. WARNING in A.java (at line 4)\n" + + " private int x;\n" + + " ^\n" + + "The field A.B.x is never read locally\n" + + "----------\n" + + "3. WARNING in A.java (at line 5)\n" + + " private C c = new C() {\n" + + " ^\n" + + "The field A.B.c is never read locally\n" + + "----------\n" + + "4. WARNING in A.java (at line 6)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type new A.C(){} is never used locally\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956 +public void test100() { + Map options = getCompilerOptions(); + CompilerOptions compOptions = new CompilerOptions(options); + if (compOptions.complianceLevel < ClassFileConstants.JDK1_4) return; + this.runNegativeTest( + new String[] { + "A.java",//------------------------------ + "public class A {\n" + + " private int x;\n" + + " private C c = new C() {\n" + + " void foo() {\n" + + " x = 3;\n" + + " }\n" + + " };\n" + + " static class C {\n" + + " private int x;\n" + + " }\n" + + " }\n", + }, + "----------\n" + + "1. WARNING in A.java (at line 2)\n" + + " private int x;\n" + + " ^\n" + + "The field A.x is never read locally\n" + + "----------\n" + + "2. WARNING in A.java (at line 3)\n" + + " private C c = new C() {\n" + + " ^\n" + + "The field A.c is never read locally\n" + + "----------\n" + + "3. WARNING in A.java (at line 4)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type new A.C(){} is never used locally\n" + + "----------\n" + + "4. WARNING in A.java (at line 5)\n" + + " x = 3;\n" + + " ^\n" + + "Write access to enclosing field A.x is emulated by a synthetic accessor method\n" + + "----------\n" + + "5. WARNING in A.java (at line 9)\n" + + " private int x;\n" + + " ^\n" + + "The field A.C.x is never read locally\n" + + "----------\n"); +} public static Class testClass() { return LookupTest.class; } }