Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 54166 Details for
Bug 165069
[1.5][compiler] incorrect field hiding
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
165069.txt (text/plain), 5.68 KB, created by
Philipe Mulet
on 2006-11-20 07:31:53 EST
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2006-11-20 07:31:53 EST
Size:
5.68 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java,v >retrieving revision 1.78 >diff -u -r1.78 FieldDeclaration.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java 13 Oct 2006 19:20:46 -0000 1.78 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java 20 Nov 2006 12:25:28 -0000 >@@ -156,28 +156,36 @@ > ClassScope classScope = initializationScope.enclosingClassScope(); > > if (classScope != null) { >- SourceTypeBinding declaringType = classScope.enclosingSourceType(); >- boolean checkLocal = true; >- if (declaringType.superclass != null) { >- Binding existingVariable = classScope.findField(declaringType.superclass, this.name, this, false /*do not resolve hidden field*/); >- if (existingVariable != null && this.binding != existingVariable && existingVariable.isValidBinding()){ >+ checkHiding: { >+ SourceTypeBinding declaringType = classScope.enclosingSourceType(); >+ checkHidingSuperField: { >+ if (declaringType.superclass == null) break checkHidingSuperField; >+ Binding existingVariable = classScope.findField(declaringType.superclass, this.name, this, false /*do not resolve hidden field*/); >+ if (existingVariable == null) break checkHidingSuperField; // keep checking outer scenario >+ if (!existingVariable.isValidBinding()) break checkHidingSuperField; // keep checking outer scenario >+ if (existingVariable instanceof FieldBinding) { >+ FieldBinding existingField = (FieldBinding) existingVariable; >+ if (existingField.original() == this.binding) break checkHidingSuperField; // keep checking outer scenario >+ } >+ // collision with supertype field > initializationScope.problemReporter().fieldHiding(this, existingVariable); >- checkLocal = false; // already found a matching field >- } >- } >- if (checkLocal) { >- Scope outerScope = classScope.parent; >+ break checkHiding; // already found a matching field >+ } > // only corner case is: lookup of outer field through static declaringType, which isn't detected by #getBinding as lookup starts > // from outer scope. Subsequent static contexts are detected for free. >- if (outerScope.kind != Scope.COMPILATION_UNIT_SCOPE) { >- Binding existingVariable = outerScope.getBinding(this.name, Binding.VARIABLE, this, false /*do not resolve hidden field*/); >- if (existingVariable != null && this.binding != existingVariable && existingVariable.isValidBinding() >- && (!(existingVariable instanceof FieldBinding) >- || ((FieldBinding) existingVariable).isStatic() >- || !declaringType.isStatic())) { >- initializationScope.problemReporter().fieldHiding(this, existingVariable); >- } >+ Scope outerScope = classScope.parent; >+ if (outerScope.kind == Scope.COMPILATION_UNIT_SCOPE) break checkHiding; >+ Binding existingVariable = outerScope.getBinding(this.name, Binding.VARIABLE, this, false /*do not resolve hidden field*/); >+ if (existingVariable == null) break checkHiding; >+ if (!existingVariable.isValidBinding()) break checkHiding; >+ if (existingVariable == this.binding) break checkHiding; >+ if (existingVariable instanceof FieldBinding) { >+ FieldBinding existingField = (FieldBinding) existingVariable; >+ if (existingField.original() == this.binding) break checkHiding; >+ if (!existingField.isStatic() && declaringType.isStatic()) break checkHiding; > } >+ // collision with outer field or local variable >+ initializationScope.problemReporter().fieldHiding(this, existingVariable); > } > } > >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java,v >retrieving revision 1.54 >diff -u -r1.54 StaticImportTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java 7 Nov 2006 18:30:50 -0000 1.54 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java 20 Nov 2006 12:25:33 -0000 >@@ -1755,4 +1755,41 @@ > "----------\n" > ); > } >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=165069 >+ public void testONLY_047() { >+ this.runNegativeTest( >+ new String[] { >+ "sample/X.java", >+ "package sample;\n" + >+ "import static sample.X.TestEnum.V1;\n" + >+ "import static sample.X.TestEnum.V2;\n" + >+ "\n" + >+ "public class X<T> {\n" + >+ " public static enum TestEnum {\n" + >+ " V1,\n" + >+ " V2\n" + >+ " }\n" + >+ "\n" + >+ " public void test(final TestEnum value) {\n" + >+ " switch (value) {\n" + >+ " case V1:\n" + >+ " case V2:\n" + >+ " }\n" + >+ " }\n" + >+ "\n" + >+ " public void ref() {\n" + >+ " final TestEnum v1 = TestEnum.V1;\n" + >+ " final TestEnum v2 = TestEnum.V2;\n" + >+ " Zork z;\n" + >+ " }\n" + >+ "}", // ================= >+ }, >+ "----------\n" + >+ "1. ERROR in sample\\X.java (at line 21)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n" >+ ); >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 165069
: 54166