Bug 537828 - Incorrect report : The field is defined in an inherited
type and an enclosing scope
Change-Id: Iffcd94658d1144fde304bd06098b613bbbdb34e7
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java
index 7b75213..5672a40 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -3492,6 +3492,43 @@
"The method foo3(Set<T>) from the type X is never used locally\n" +
"----------\n");
}
+
+public void testBug527828() {
+ Map options = getCompilerOptions();
+ CompilerOptions compOptions = new CompilerOptions(options);
+ if (compOptions.complianceLevel < ClassFileConstants.JDK1_4) return;
+ this.runNegativeTest(
+ new String[] {
+ "FieldBug.java",//------------------------------
+ "class A {\n" +
+ " Object obj = \"A.obj\";\n" +
+ "}\n" +
+ "\n" +
+ "class B {\n" +
+ " private Object obj = \"B.obj\";\n" +
+ "}\n" +
+ "\n" +
+ "public class FieldBug {\n" +
+ " Object obj = \"FieldBug.obj\";\n" +
+ "\n" +
+ " static class AA extends A {\n" +
+ " class BB extends B {\n" +
+ " Object n = obj;\n" +
+ " }\n" +
+ " }\n" +
+ " \n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(new AA().new BB().n);\n" +
+ " }\n" +
+ "}",
+ },
+ "----------\n" +
+ "1. WARNING in FieldBug.java (at line 6)\n" +
+ " private Object obj = \"B.obj\";\n" +
+ " ^^^\n" +
+ "The value of the field B.obj is not used\n" +
+ "----------\n");
+}
public static Class testClass() { return LookupTest.class;
}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
index baa3395..efda88d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java
@@ -2136,7 +2136,7 @@
if (TypeBinding.equalsEquals(receiverType, fieldBinding.declaringClass) || compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) {
// found a valid field in the 'immediate' scope (i.e. not inherited)
// OR in 1.4 mode (inherited shadows enclosing)
- if (foundField == null) {
+ if (foundField == null || foundField.problemId() == ProblemReasons.NotVisible) {
if (depth > 0){
invocationSite.setDepth(depth);
invocationSite.setActualReceiverType(receiverType);