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 118188 Details for
Bug 255452
[1.5][compiler] Eclipse allows forward reference in enum constructor
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Better patch
255452.txt (text/plain), 30.84 KB, created by
Philipe Mulet
on 2008-11-18 15:21:54 EST
(
hide
)
Description:
Better patch
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2008-11-18 15:21:54 EST
Size:
30.84 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests >Index: Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/InitializationTest.java >=================================================================== >RCS file: /home/cvs/numbat/org.eclipse.jdt.core.tests/Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/InitializationTest.java,v >retrieving revision 1.118 >diff -u -r1.118 InitializationTest.java >--- Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/InitializationTest.java 3 Nov 2008 10:15:34 -0000 1.118 >+++ Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/InitializationTest.java 18 Nov 2008 20:11:13 -0000 >@@ -1557,18 +1557,17 @@ > " X x = new X(x.i); // should notice illegal forward reference.\n"+ > "} \n" > }, >- "----------\n" + >- "1. ERROR in X.java (at line 5)\n" + >- " X z = z.i; \n" + >- " ^^^\n" + >- "Cannot reference a field before it is defined\n" + >- "----------\n" + >- "2. ERROR in X.java (at line 6)\n" + >- " X x = new X(x.i); // should notice illegal forward reference.\n" + >- " ^^^\n" + >- "Cannot reference a field before it is defined\n" + >- "----------\n" >- ); >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " X z = z.i; \n" + >+ " ^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 6)\n" + >+ " X x = new X(x.i); // should notice illegal forward reference.\n" + >+ " ^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n"); > } > /** > * 1EUFH3W: IVJCOM:WINNT - final variable with static/instance >@@ -1586,16 +1585,16 @@ > " } \n"+ > "}\n" > }, >- "----------\n" + >- "1. ERROR in B.java (at line 2)\n" + >- " static B b = a.b; \n" + >- " ^^^\n" + >- "Cannot reference a field before it is defined\n" + >- "----------\n" + >- "2. WARNING in B.java (at line 2)\n" + >- " static B b = a.b; \n" + >- " ^\n" + >- "The static field B.b should be accessed in a static way\n" + >+ "----------\n" + >+ "1. ERROR in B.java (at line 2)\n" + >+ " static B b = a.b; \n" + >+ " ^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "2. WARNING in B.java (at line 2)\n" + >+ " static B b = a.b; \n" + >+ " ^\n" + >+ "The static field B.b should be accessed in a static way\n" + > "----------\n"); > } > /** >#P org.eclipse.jdt.core >Index: buildnotes_jdt-core.html >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/buildnotes_jdt-core.html,v >retrieving revision 1.6755 >diff -u -r1.6755 buildnotes_jdt-core.html >--- buildnotes_jdt-core.html 18 Nov 2008 10:10:46 -0000 1.6755 >+++ buildnotes_jdt-core.html 18 Nov 2008 20:11:18 -0000 >@@ -39,11 +39,24 @@ > </td> > </tr> > </table> >+<a name="v_926"></a> >+<hr><h1> >+Eclipse Platform Build Notes<br> >+Java Development Tooling Core</h1> >+Eclipse SDK 3.5M4 - %date% - 3.5 MILESTONE 4 >+<br>Project org.eclipse.jdt.core v_926 >+(<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_926">cvs</a>). >+<h2>What's new in this drop</h2> >+ >+<h3>Problem Reports Fixed</h3> >+<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=255452">255452</a> >+[1.5][compiler] Eclipse allows forward reference in enum constructor >+ > <a name="v_925"></a> > <hr><h1> > Eclipse Platform Build Notes<br> > Java Development Tooling Core</h1> >-Eclipse SDK 3.5M4 - November 18, 2008 - 3.5 MILESTONE 4 >+Eclipse SDK 3.5M4 - November 18, 2008 > <br>Project org.eclipse.jdt.core v_925 > (<a href="http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.core/?only_with_tag=v_925">cvs</a>). > <h2>What's new in this drop</h2> >Index: batch/org/eclipse/jdt/internal/compiler/batch/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties,v >retrieving revision 1.780 >diff -u -r1.780 messages.properties >--- batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 12 Nov 2008 00:43:25 -0000 1.780 >+++ batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 18 Nov 2008 20:11:20 -0000 >@@ -15,7 +15,7 @@ > #Format: compiler.name = word1 word2 word3 > compiler.name = Eclipse Java Compiler > #Format: compiler.version = 0.XXX[, other words (don't forget the comma if adding other words)] >-compiler.version = 0.925, 3.5.0 milestone-4 >+compiler.version = 0.926, 3.5.0 milestone-4 > compiler.copyright = Copyright IBM Corp 2000, 2008. All rights reserved. > > ### progress >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.113 >diff -u -r1.113 SingleNameReference.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 2 Oct 2008 00:46:27 -0000 1.113 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/SingleNameReference.java 18 Nov 2008 20:11:24 -0000 >@@ -209,7 +209,7 @@ > && methodScope.lastVisibleFieldID >= 0 > && fieldBinding.id >= methodScope.lastVisibleFieldID > && (!fieldBinding.isStatic() || methodScope.isStatic)) { >- scope.problemReporter().forwardReference(this, 0, methodScope.enclosingSourceType()); >+ scope.problemReporter().forwardReference(this, 0, fieldBinding); > this.bits |= ASTNode.IgnoreNoEffectAssignCheck; > } > return fieldBinding.type; >Index: compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java,v >retrieving revision 1.136 >diff -u -r1.136 QualifiedNameReference.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java 5 Nov 2008 00:36:27 -0000 1.136 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedNameReference.java 18 Nov 2008 20:11:23 -0000 >@@ -209,25 +209,6 @@ > return flowInfo; > } > >-/** >- * Check and/or redirect the field access to the delegate receiver if any >- */ >-public TypeBinding checkFieldAccess(BlockScope scope) { >- FieldBinding fieldBinding = (FieldBinding) this.binding; >- MethodScope methodScope = scope.methodScope(); >- // check for forward references >- if (this.indexOfFirstFieldBinding == 1 >- && methodScope.enclosingSourceType() == fieldBinding.original().declaringClass >- && methodScope.lastVisibleFieldID >= 0 >- && fieldBinding.id >= methodScope.lastVisibleFieldID >- && (!fieldBinding.isStatic() || methodScope.isStatic)) { >- scope.problemReporter().forwardReference(this, 0, methodScope.enclosingSourceType()); >- } >- this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits >- this.bits |= Binding.FIELD; >- return getOtherFieldBindings(scope); >-} >- > public void checkNPE(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo, boolean checkString) { > // cannot override localVariableBinding because this would project o.m onto o when > // analysing assignments >@@ -682,27 +663,7 @@ > public TypeBinding getOtherFieldBindings(BlockScope scope) { > // At this point restrictiveFlag may ONLY have two potential value : FIELD LOCAL (i.e cast <<(VariableBinding) binding>> is valid) > int length = this.tokens.length; >- FieldBinding field; >- if ((this.bits & Binding.FIELD) != 0) { >- field = (FieldBinding) this.binding; >- if (!field.isStatic()) { >- //must check for the static status.... >- if (this.indexOfFirstFieldBinding > 1 //accessing to a field using a type as "receiver" is allowed only with static field >- || scope.methodScope().isStatic) { // the field is the first token of the qualified reference.... >- scope.problemReporter().staticFieldAccessToNonStaticVariable(this, field); >- return null; >- } >- } else if (this.indexOfFirstFieldBinding > 1 >- && field.declaringClass != this.actualReceiverType >- && field.declaringClass.canBeSeenBy(scope)) { >- scope.problemReporter().indirectAccessToStaticField(this, field); >- } >- // only last field is actually a write access if any >- if (isFieldUseDeprecated(field, scope, (this.bits & ASTNode.IsStrictlyAssigned) != 0 && this.indexOfFirstFieldBinding == length)) >- scope.problemReporter().deprecatedField(field, this); >- } else { >- field = null; >- } >+ FieldBinding field = ((this.bits & Binding.FIELD) != 0) ? (FieldBinding) this.binding : null; > TypeBinding type = ((VariableBinding) this.binding).type; > int index = this.indexOfFirstFieldBinding; > if (index == length) { // restrictiveFlag == FIELD >@@ -754,11 +715,18 @@ > } > > if (field.isStatic()) { >- // check if accessing enum static field in initializer >- ReferenceBinding declaringClass = field.declaringClass; >+ ReferenceBinding declaringClass = field.original().declaringClass; > if (declaringClass.isEnum()) { > MethodScope methodScope = scope.methodScope(); > SourceTypeBinding sourceType = methodScope.enclosingSourceType(); >+ if ((this.bits & ASTNode.IsStrictlyAssigned) == 0 >+ && sourceType == declaringClass >+ && methodScope.lastVisibleFieldID >= 0 >+ && field.id >= methodScope.lastVisibleFieldID >+ && (!field.isStatic() || methodScope.isStatic)) { >+ scope.problemReporter().forwardReference(this, index, field); >+ } >+ // check if accessing enum static field in initializer > if ((sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body > && field.constant() == Constant.NotAConstant > && !methodScope.isStatic >@@ -931,18 +899,18 @@ > case Binding.VARIABLE : //============only variable=========== > case Binding.TYPE | Binding.VARIABLE : > if (this.binding instanceof LocalVariableBinding) { >- LocalVariableBinding local = (LocalVariableBinding) this.binding; >- if (!local.isFinal() && ((this.bits & ASTNode.DepthMASK) != 0)) >- scope.problemReporter().cannotReferToNonFinalOuterLocal((LocalVariableBinding) this.binding, this); > this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits > this.bits |= Binding.LOCAL; >+ LocalVariableBinding local = (LocalVariableBinding) this.binding; >+ if (!local.isFinal() && ((this.bits & ASTNode.DepthMASK) != 0)) { >+ scope.problemReporter().cannotReferToNonFinalOuterLocal((LocalVariableBinding) this.binding, this); >+ } > if (local.type != null && (local.type.tagBits & TagBits.HasMissingType) != 0) { > // only complain if field reference (for local, its type got flagged already) > return null; > } > this.resolvedType = getOtherFieldBindings(scope); >- if (this.resolvedType != null >- && (this.resolvedType.tagBits & TagBits.HasMissingType) != 0) { >+ if (this.resolvedType != null && (this.resolvedType.tagBits & TagBits.HasMissingType) != 0) { > FieldBinding lastField = this.otherBindings[this.otherBindings.length - 1]; > scope.problemReporter().invalidField(this, new ProblemFieldBinding(lastField.declaringClass, lastField.name, ProblemReasons.NotFound), this.tokens.length, this.resolvedType.leafComponentType()); > return null; >@@ -950,21 +918,27 @@ > return this.resolvedType; > } > if (this.binding instanceof FieldBinding) { >+ this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits >+ this.bits |= Binding.FIELD; > FieldBinding fieldBinding = (FieldBinding) this.binding; > MethodScope methodScope = scope.methodScope(); >+ ReferenceBinding declaringClass = fieldBinding.original().declaringClass; >+ SourceTypeBinding sourceType = methodScope.enclosingSourceType(); > // check for forward references >- if (this.indexOfFirstFieldBinding == 1 >- && methodScope.enclosingSourceType() == fieldBinding.original().declaringClass >+ if ((this.indexOfFirstFieldBinding == 1 || declaringClass.isEnum()) >+ && sourceType == declaringClass > && methodScope.lastVisibleFieldID >= 0 > && fieldBinding.id >= methodScope.lastVisibleFieldID > && (!fieldBinding.isStatic() || methodScope.isStatic)) { >- scope.problemReporter().forwardReference(this, 0, methodScope.enclosingSourceType()); >+ scope.problemReporter().forwardReference(this, this.indexOfFirstFieldBinding-1, fieldBinding); >+ } >+ if (isFieldUseDeprecated(fieldBinding, scope, (this.bits & ASTNode.IsStrictlyAssigned) != 0 && this.indexOfFirstFieldBinding == this.tokens.length)) { >+ scope.problemReporter().deprecatedField(fieldBinding, this); > } > if (fieldBinding.isStatic()) { >- ReferenceBinding declaringClass = fieldBinding.declaringClass; >+ // only last field is actually a write access if any > // check if accessing enum static field in initializer > if (declaringClass.isEnum()) { >- SourceTypeBinding sourceType = methodScope.enclosingSourceType(); > if ((sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body > && fieldBinding.constant() == Constant.NotAConstant > && !methodScope.isStatic >@@ -972,18 +946,23 @@ > scope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this); > } > } >- } else if (this.indexOfFirstFieldBinding == 1 && scope.compilerOptions().getSeverity(CompilerOptions.UnqualifiedFieldAccess) != ProblemSeverities.Ignore) { >- scope.problemReporter().unqualifiedFieldAccess(this, fieldBinding); >+ if (this.indexOfFirstFieldBinding > 1 >+ && fieldBinding.declaringClass != this.actualReceiverType >+ && fieldBinding.declaringClass.canBeSeenBy(scope)) { >+ scope.problemReporter().indirectAccessToStaticField(this, fieldBinding); >+ } >+ } else { >+ if (this.indexOfFirstFieldBinding == 1 && scope.compilerOptions().getSeverity(CompilerOptions.UnqualifiedFieldAccess) != ProblemSeverities.Ignore) { >+ scope.problemReporter().unqualifiedFieldAccess(this, fieldBinding); >+ } >+ //must check for the static status.... >+ if (this.indexOfFirstFieldBinding > 1 //accessing to a field using a type as "receiver" is allowed only with static field >+ || scope.methodScope().isStatic) { // the field is the first token of the qualified reference.... >+ scope.problemReporter().staticFieldAccessToNonStaticVariable(this, fieldBinding); >+ return null; >+ } > } >- this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits >- this.bits |= Binding.FIELD; >- >-// // check for deprecated receiver type >-// // deprecation check for receiver type if not first token >-// if (indexOfFirstFieldBinding > 1) { >-// if (isTypeUseDeprecated(this.actualReceiverType, scope)) >-// scope.problemReporter().deprecatedType(this.actualReceiverType, this); >-// } >+ > this.resolvedType = getOtherFieldBindings(scope); > if (this.resolvedType != null > && (this.resolvedType.tagBits & TagBits.HasMissingType) != 0) { >Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java,v >retrieving revision 1.380 >diff -u -r1.380 ProblemReporter.java >--- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 10 Oct 2008 17:24:31 -0000 1.380 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 18 Nov 2008 20:11:42 -0000 >@@ -1778,13 +1778,13 @@ > location.sourceStart, > location.sourceEnd); > } >-public void forwardReference(Reference reference, int indexInQualification, TypeBinding type) { >+public void forwardReference(Reference reference, int indexInQualification, FieldBinding field) { > this.handle( > IProblem.ReferenceToForwardField, > NoArgument, > NoArgument, >- reference.sourceStart, >- reference.sourceEnd); >+ nodeSourceStart(field, reference, indexInQualification), >+ nodeSourceEnd(field, reference, indexInQualification)); > } > public void forwardTypeVariableReference(ASTNode location, TypeVariableBinding type) { > this.handle( >Index: eval/org/eclipse/jdt/internal/eval/CodeSnippetQualifiedNameReference.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetQualifiedNameReference.java,v >retrieving revision 1.58 >diff -u -r1.58 CodeSnippetQualifiedNameReference.java >--- eval/org/eclipse/jdt/internal/eval/CodeSnippetQualifiedNameReference.java 25 Sep 2008 23:10:29 -0000 1.58 >+++ eval/org/eclipse/jdt/internal/eval/CodeSnippetQualifiedNameReference.java 18 Nov 2008 20:11:43 -0000 >@@ -10,6 +10,7 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.eval; > >+import org.eclipse.jdt.internal.compiler.ast.ASTNode; > import org.eclipse.jdt.internal.compiler.ast.Assignment; > import org.eclipse.jdt.internal.compiler.ast.CompoundAssignment; > import org.eclipse.jdt.internal.compiler.ast.Expression; >@@ -25,6 +26,7 @@ > import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; > import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; > import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; >+import org.eclipse.jdt.internal.compiler.lookup.MethodScope; > import org.eclipse.jdt.internal.compiler.lookup.ProblemBinding; > import org.eclipse.jdt.internal.compiler.lookup.ProblemFieldBinding; > import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons; >@@ -47,6 +49,27 @@ > super(sources, positions, sourceStart, sourceEnd); > this.evaluationContext = evaluationContext; > } >+ >+/** >+ * Check and/or redirect the field access to the delegate receiver if any >+ */ >+public TypeBinding checkFieldAccess(BlockScope scope) { >+ FieldBinding fieldBinding = (FieldBinding) this.binding; >+ MethodScope methodScope = scope.methodScope(); >+ TypeBinding declaringClass = fieldBinding.original().declaringClass; >+ // check for forward references >+ if ((this.indexOfFirstFieldBinding == 1 || declaringClass.isEnum()) >+ && methodScope.enclosingSourceType() == declaringClass >+ && methodScope.lastVisibleFieldID >= 0 >+ && fieldBinding.id >= methodScope.lastVisibleFieldID >+ && (!fieldBinding.isStatic() || methodScope.isStatic)) { >+ scope.problemReporter().forwardReference(this, this.indexOfFirstFieldBinding-1, fieldBinding); >+ } >+ this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits >+ this.bits |= Binding.FIELD; >+ return getOtherFieldBindings(scope); >+} >+ > public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { > int pc = codeStream.position; > if ((this.bits & Binding.VARIABLE) == 0) { // nothing to do if type ref >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java,v >retrieving revision 1.135 >diff -u -r1.135 EnumTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java 23 Oct 2008 17:22:28 -0000 1.135 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java 18 Nov 2008 20:12:00 -0000 >@@ -5939,4 +5939,156 @@ > false, > false); > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=255452 >+public void test168() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", // ================= >+ "enum BadEnum {\n" + >+ " CRAZY(CRAZY), // <-- illegal forward reference reported by all compilers\n" + >+ " IMPOSSIBLE(BadEnum.IMPOSSIBLE); // <-- illegal forward reference (javac 1.6 only)\n" + >+ " private BadEnum(BadEnum self) {\n" + >+ " }\n" + >+ "}\n" + >+ "public class X {\n" + >+ " X x1 = new X(x1);//1 - WRONG\n" + >+ " static X X2 = new X(X.X2);//2 - OK\n" + >+ " X x3 = new X(this.x3);//3 - OK\n" + >+ " X(X x) {}\n" + >+ " X(int i) {}\n" + >+ " static int VALUE() { return 13; }\n" + >+ " int value() { return 14; }\n" + >+ "}\n" + >+ "class Y extends X {\n" + >+ " X x1 = new X(x1);//6 - WRONG\n" + >+ " static X X2 = new X(Y.X2);//7 - OK\n" + >+ " X x3 = new X(this.x3);//8 - OK\n" + >+ " Y(Y y) { super(y); }\n" + >+ "}\n", // ================= >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 2)\n" + >+ " CRAZY(CRAZY), // <-- illegal forward reference reported by all compilers\n" + >+ " ^^^^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 3)\n" + >+ " IMPOSSIBLE(BadEnum.IMPOSSIBLE); // <-- illegal forward reference (javac 1.6 only)\n" + >+ " ^^^^^^^^^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 8)\n" + >+ " X x1 = new X(x1);//1 - WRONG\n" + >+ " ^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 17)\n" + >+ " X x1 = new X(x1);//6 - WRONG\n" + >+ " ^^\n" + >+ "The field Y.x1 is hiding a field from type X\n" + >+ "----------\n" + >+ "5. ERROR in X.java (at line 17)\n" + >+ " X x1 = new X(x1);//6 - WRONG\n" + >+ " ^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "6. WARNING in X.java (at line 18)\n" + >+ " static X X2 = new X(Y.X2);//7 - OK\n" + >+ " ^^\n" + >+ "The field Y.X2 is hiding a field from type X\n" + >+ "----------\n" + >+ "7. WARNING in X.java (at line 19)\n" + >+ " X x3 = new X(this.x3);//8 - OK\n" + >+ " ^^\n" + >+ "The field Y.x3 is hiding a field from type X\n" + >+ "----------\n"); > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=255452 - variation >+public void test169() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", // ================= >+ "enum BadEnum {\n" + >+ " NOWAY(BadEnum.NOWAY.CONST),\n" + >+ " INVALID(INVALID.CONST),\n" + >+ " WRONG(WRONG.VALUE()),\n" + >+ " ILLEGAL(ILLEGAL.value());\n" + >+ " final static int CONST = 12;\n" + >+ " private BadEnum(int i) {\n" + >+ " }\n" + >+ " static int VALUE() { return 13; }\n" + >+ " int value() { return 14; }\n" + >+ "}\n" + >+ "public class X {\n" + >+ " final static int CONST = 12;\n" + >+ " X x4 = new X(x4.CONST);//4 - WRONG\n" + >+ " X x5 = new X(x5.value());//5 - WRONG\n" + >+ " X(int i) {}\n" + >+ " static int VALUE() { return 13; }\n" + >+ " int value() { return 14; }\n" + >+ "}\n", // ================= >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 2)\n" + >+ " NOWAY(BadEnum.NOWAY.CONST),\n" + >+ " ^^^^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 2)\n" + >+ " NOWAY(BadEnum.NOWAY.CONST),\n" + >+ " ^^^^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 2)\n" + >+ " NOWAY(BadEnum.NOWAY.CONST),\n" + >+ " ^^^^^\n" + >+ "The static field BadEnum.CONST should be accessed in a static way\n" + >+ "----------\n" + >+ "4. ERROR in X.java (at line 3)\n" + >+ " INVALID(INVALID.CONST),\n" + >+ " ^^^^^^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "5. ERROR in X.java (at line 3)\n" + >+ " INVALID(INVALID.CONST),\n" + >+ " ^^^^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "6. WARNING in X.java (at line 3)\n" + >+ " INVALID(INVALID.CONST),\n" + >+ " ^^^^^\n" + >+ "The static field BadEnum.CONST should be accessed in a static way\n" + >+ "----------\n" + >+ "7. ERROR in X.java (at line 4)\n" + >+ " WRONG(WRONG.VALUE()),\n" + >+ " ^^^^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "8. WARNING in X.java (at line 4)\n" + >+ " WRONG(WRONG.VALUE()),\n" + >+ " ^^^^^^^^^^^^^\n" + >+ "The static method VALUE() from the type BadEnum should be accessed in a static way\n" + >+ "----------\n" + >+ "9. ERROR in X.java (at line 5)\n" + >+ " ILLEGAL(ILLEGAL.value());\n" + >+ " ^^^^^^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "10. ERROR in X.java (at line 14)\n" + >+ " X x4 = new X(x4.CONST);//4 - WRONG\n" + >+ " ^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "11. WARNING in X.java (at line 14)\n" + >+ " X x4 = new X(x4.CONST);//4 - WRONG\n" + >+ " ^^^^^\n" + >+ "The static field X.CONST should be accessed in a static way\n" + >+ "----------\n" + >+ "12. ERROR in X.java (at line 15)\n" + >+ " X x5 = new X(x5.value());//5 - WRONG\n" + >+ " ^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n"); >+} >+} >+ >Index: src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java,v >retrieving revision 1.766 >diff -u -r1.766 GenericTypeTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 17 Nov 2008 15:57:12 -0000 1.766 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 18 Nov 2008 20:13:56 -0000 >@@ -36438,41 +36438,41 @@ > " E e2 = e2.e;\n" + > "}", // ================= > }, >- "----------\n" + >- "1. ERROR in Y.java (at line 2)\n" + >- " Z z1 = z1;\n" + >- " ^^\n" + >- "Cannot reference a field before it is defined\n" + >- "----------\n" + >- "2. ERROR in Y.java (at line 3)\n" + >- " Z[] z2 = z2;\n" + >- " ^^\n" + >- "Cannot reference a field before it is defined\n" + >- "----------\n" + >- "3. ERROR in Y.java (at line 6)\n" + >- " E e0 = es[0];\n" + >- " ^^\n" + >- "Cannot reference a field before it is defined\n" + >- "----------\n" + >- "4. ERROR in Y.java (at line 7)\n" + >- " E e = e;\n" + >- " ^\n" + >- "Cannot reference a field before it is defined\n" + >- "----------\n" + >- "5. ERROR in Y.java (at line 8)\n" + >- " E[] es = es;\n" + >- " ^^\n" + >- "Cannot reference a field before it is defined\n" + >- "----------\n" + >- "6. ERROR in Y.java (at line 9)\n" + >- " E e2 = e2.e;\n" + >- " ^^^^\n" + >- "Cannot reference a field before it is defined\n" + >- "----------\n" + >- "7. ERROR in Y.java (at line 9)\n" + >- " E e2 = e2.e;\n" + >- " ^^^^\n" + >- "e2.e cannot be resolved or is not a field\n" + >+ "----------\n" + >+ "1. ERROR in Y.java (at line 2)\n" + >+ " Z z1 = z1;\n" + >+ " ^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "2. ERROR in Y.java (at line 3)\n" + >+ " Z[] z2 = z2;\n" + >+ " ^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "3. ERROR in Y.java (at line 6)\n" + >+ " E e0 = es[0];\n" + >+ " ^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "4. ERROR in Y.java (at line 7)\n" + >+ " E e = e;\n" + >+ " ^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "5. ERROR in Y.java (at line 8)\n" + >+ " E[] es = es;\n" + >+ " ^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "6. ERROR in Y.java (at line 9)\n" + >+ " E e2 = e2.e;\n" + >+ " ^^\n" + >+ "Cannot reference a field before it is defined\n" + >+ "----------\n" + >+ "7. ERROR in Y.java (at line 9)\n" + >+ " E e2 = e2.e;\n" + >+ " ^^^^\n" + >+ "e2.e cannot be resolved or is not a field\n" + > "----------\n"); > } > >@@ -47643,4 +47643,49 @@ > }, > ""); > } >+public void test1407() { >+ this.runNegativeTest( >+ new String[] { >+ "Foo.java", //----------------------------------------------------------------------- >+ "public class Foo {\n" + >+ " public static <I> I m1(Class<Foo> c) { return null; }\n" + >+ " public static <I> I m2(Class<I> c) { return null; } \n" + >+ " void bar() {\n" + >+ " Foo l1 = m1((Class)Foo.class); //ok - unchecked conversion from Class to Class<Foo> - I inferred to be Foo\n" + >+ " Foo l2 = m2((Class)Foo.class); //unchecked call, erased return type and error because Object != Foo \n" + >+ " }\n" + >+ "}\n",//----------------------------------------------------------------------- >+ }, >+ "----------\n" + >+ "1. WARNING in Foo.java (at line 5)\n" + >+ " Foo l1 = m1((Class)Foo.class); //ok - unchecked conversion from Class to Class<Foo> - I inferred to be Foo\n" + >+ " ^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The expression of type Class needs unchecked conversion to conform to Class<Foo>\n" + >+ "----------\n" + >+ "2. WARNING in Foo.java (at line 5)\n" + >+ " Foo l1 = m1((Class)Foo.class); //ok - unchecked conversion from Class to Class<Foo> - I inferred to be Foo\n" + >+ " ^^^^^\n" + >+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" + >+ "----------\n" + >+ "3. WARNING in Foo.java (at line 6)\n" + >+ " Foo l2 = m2((Class)Foo.class); //unchecked call, erased return type and error because Object != Foo \n" + >+ " ^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: Unchecked invocation m2(Class) of the generic method m2(Class<I>) of type Foo\n" + >+ "----------\n" + >+ "4. ERROR in Foo.java (at line 6)\n" + >+ " Foo l2 = m2((Class)Foo.class); //unchecked call, erased return type and error because Object != Foo \n" + >+ " ^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type mismatch: cannot convert from Object to Foo\n" + >+ "----------\n" + >+ "5. WARNING in Foo.java (at line 6)\n" + >+ " Foo l2 = m2((Class)Foo.class); //unchecked call, erased return type and error because Object != Foo \n" + >+ " ^^^^^^^^^^^^^^^^\n" + >+ "Type safety: The expression of type Class needs unchecked conversion to conform to Class<I>\n" + >+ "----------\n" + >+ "6. WARNING in Foo.java (at line 6)\n" + >+ " Foo l2 = m2((Class)Foo.class); //unchecked call, erased return type and error because Object != Foo \n" + >+ " ^^^^^\n" + >+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" + >+ "----------\n"); >+} > } >\ No newline at end of file
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 255452
:
118059
| 118188 |
118206