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 79165 Details for
Bug 204536
[1.5][compiler] Type variables insufficiently connected in presence of errors
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Better patch/2
204536.txt (text/plain), 16.61 KB, created by
Philipe Mulet
on 2007-09-25 16:06:07 EDT
(
hide
)
Description:
Better patch/2
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2007-09-25 16:06:07 EDT
Size:
16.61 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.compiler >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.647 >diff -u -r1.647 GenericTypeTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 25 Sep 2007 09:29:17 -0000 1.647 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 25 Sep 2007 20:03:56 -0000 >@@ -39346,4 +39346,165 @@ > }, > ""); > } >+public void test1179() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<T extends Object&V, V> {}\n" + >+ "\n", // ================= >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 1)\n" + >+ " public class X<T extends Object&V, V> {}\n" + >+ " ^\n" + >+ "The type V is not an interface; it cannot be specified as a bounded parameter\n" + >+ "----------\n"); >+} >+public void test1180() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static <S, T extends Comparable<S>, R extends S & T> R max1(T arg1, S arg2) {\n" + >+ " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + >+ " }\n" + >+ "\n" + >+ " public static <T extends Comparable<S>, S, R extends S & Comparable<S>> R max2(T arg1, S arg2) {\n" + >+ " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + >+ " }\n" + >+ "\n" + >+ " public static <T extends Comparable<S>, S, R extends Comparable<S>> R max3(T arg1, S arg2) {\n" + >+ " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + >+ " }\n" + >+ "\n" + >+ " public static void main(String[] args) {\n" + >+ " }\n" + >+ "}\n", // ================= >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 2)\n" + >+ " public static <S, T extends Comparable<S>, R extends S & T> R max1(T arg1, S arg2) {\n" + >+ " ^\n" + >+ "Cannot specify any additional bound T when first bound is a type parameter\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 3)\n" + >+ " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: Unchecked cast from Object to R\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 6)\n" + >+ " public static <T extends Comparable<S>, S, R extends S & Comparable<S>> R max2(T arg1, S arg2) {\n" + >+ " ^^^^^^^^^^\n" + >+ "Cannot specify any additional bound Comparable<S> when first bound is a type parameter\n" + >+ "----------\n" + >+ "4. WARNING in X.java (at line 7)\n" + >+ " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: Unchecked cast from Object to R\n" + >+ "----------\n" + >+ "5. WARNING in X.java (at line 11)\n" + >+ " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Type safety: Unchecked cast from Object to R\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204534 >+public void _test1181() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static <S, T extends Comparable<S>, R extends S & T> R max(T arg1, S arg2) {\n" + >+ " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + >+ " }\n" + >+ "\n" + >+ " public static <T extends Comparable<S>, S, R extends S & Comparable<S>> R max(T arg1, S arg2) {\n" + >+ " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + >+ " }\n" + >+ "\n" + >+ " public static <T extends Comparable<S>, S, R extends Comparable<S>> R max(T arg1, S arg2) {\n" + >+ " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + >+ " }\n" + >+ "\n" + >+ " public static void main(String[] args) {\n" + >+ " }\n" + >+ "}\n", // ================= >+ }, >+ "should not see errors like: R cannot be resolved to a type"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204536 >+public void test1182() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<T extends Zork & Zork & Object> {\n" + >+ "}\n", // ================= >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 1)\n" + >+ " public class X<T extends Zork & Zork & Object> {\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 1)\n" + >+ " public class X<T extends Zork & Zork & Object> {\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 1)\n" + >+ " public class X<T extends Zork & Zork & Object> {\n" + >+ " ^^^^^^\n" + >+ "The type Object is not an interface; it cannot be specified as a bounded parameter\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204536 - variation >+public void test1183() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<T extends Zork & Runnable> {\n" + >+ " void foo(T t) {\n" + >+ " t.run();\n" + >+ " }\n" + >+ " \n" + >+ "}\n", // ================= >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 1)\n" + >+ " public class X<T extends Zork & Runnable> {\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204536 - variation >+public void test1184() { >+ // check that unresolved first bound got erased into Object (and not Runnable) >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<T extends Zork & Runnable> {\n" + >+ " T get() { return null; }\n" + >+ " void foo(X x) {\n" + >+ " Runnable r = x.get();\n" + >+ " }\n" + >+ " \n" + >+ "}\n", // ================= >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 1)\n" + >+ " public class X<T extends Zork & Runnable> {\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 3)\n" + >+ " void foo(X x) {\n" + >+ " ^\n" + >+ "X is a raw type. References to generic type X<T> should be parameterized\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 4)\n" + >+ " Runnable r = x.get();\n" + >+ " ^^^^^^^\n" + >+ "Type mismatch: cannot convert from Object to Runnable\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.6087 >diff -u -r1.6087 buildnotes_jdt-core.html >--- buildnotes_jdt-core.html 25 Sep 2007 15:33:40 -0000 1.6087 >+++ buildnotes_jdt-core.html 25 Sep 2007 20:03:59 -0000 >@@ -53,6 +53,7 @@ > > <h3>Problem Reports Fixed</h3> > <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=154071">154071</a> >+<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=154071">154071</a> > No notification of change if a project is added or removed from a container > > <a name="v_815"></a> >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.313 >diff -u -r1.313 Scope.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 24 Sep 2007 22:49:54 -0000 1.313 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 25 Sep 2007 20:04:00 -0000 >@@ -447,11 +447,16 @@ > return null; // incompatible > } > >+ /** >+ * Connect type variable supertypes, and returns true if no problem was detected >+ * @param typeParameters >+ * @param checkForErasedCandidateCollisions >+ */ > protected boolean connectTypeVariables(TypeParameter[] typeParameters, boolean checkForErasedCandidateCollisions) { > if (typeParameters == null || compilerOptions().sourceLevel < ClassFileConstants.JDK1_5) return true; >- boolean noProblems = true; > Map invocations = new HashMap(2); >- nextVariable : for (int i = 0, paramLength = typeParameters.length; i < paramLength; i++) { >+ boolean noProblems = true; >+ nextVariable: for (int i = 0, paramLength = typeParameters.length; i < paramLength; i++) { > TypeParameter typeParameter = typeParameters[i]; > TypeVariableBinding typeVariable = typeParameter.binding; > if (typeVariable == null) return false; >@@ -464,93 +469,105 @@ > TypeReference typeRef = typeParameter.type; > if (typeRef == null) > continue nextVariable; >+ boolean isFirstBoundTypeVariable = false; > TypeBinding superType = this.kind == METHOD_SCOPE > ? typeRef.resolveType((BlockScope)this, false/*no bound check*/) > : typeRef.resolveType((ClassScope)this); > if (superType == null) { > typeVariable.tagBits |= TagBits.HierarchyHasProblems; >- noProblems = false; >- continue nextVariable; >- } >- typeRef.resolvedType = superType; // hold onto the problem type >- if (superType.isArrayType()) { >- problemReporter().boundCannotBeArray(typeRef, superType); >- continue nextVariable; >- } >- boolean isTypeVariableFirstBound = superType.isTypeVariable(); >- if (isTypeVariableFirstBound) { >- TypeVariableBinding varSuperType = (TypeVariableBinding) superType; >- if (varSuperType.rank >= typeVariable.rank && varSuperType.declaringElement == typeVariable.declaringElement) { >- problemReporter().forwardTypeVariableReference(typeParameter, varSuperType); >- typeVariable.tagBits |= TagBits.HierarchyHasProblems; >- noProblems = false; >- continue nextVariable; >- } >- } >- ReferenceBinding superRefType = (ReferenceBinding) superType; >- if (superRefType.isFinal()) >- problemReporter().finalVariableBound(typeVariable, typeRef); >- if (!superType.isInterface()) { >- typeVariable.superclass = superRefType; > } else { >- typeVariable.superInterfaces = new ReferenceBinding[] {superRefType}; >+ typeRef.resolvedType = superType; // hold onto the problem type >+ firstBound: { >+ switch (superType.kind()) { >+ case Binding.ARRAY_TYPE : >+ problemReporter().boundCannotBeArray(typeRef, superType); >+ typeVariable.tagBits |= TagBits.HierarchyHasProblems; >+ break firstBound; // do not keep first bound >+ case Binding.TYPE_PARAMETER : >+ isFirstBoundTypeVariable = true; >+ TypeVariableBinding varSuperType = (TypeVariableBinding) superType; >+ if (varSuperType.rank >= typeVariable.rank && varSuperType.declaringElement == typeVariable.declaringElement) { >+ problemReporter().forwardTypeVariableReference(typeParameter, varSuperType); >+ typeVariable.tagBits |= TagBits.HierarchyHasProblems; >+ break firstBound; // do not keep first bound >+ } >+ break; >+ default : >+ if (((ReferenceBinding) superType).isFinal()) { >+ problemReporter().finalVariableBound(typeVariable, typeRef); >+ } >+ break; >+ } >+ ReferenceBinding superRefType = (ReferenceBinding) superType; >+ if (!superType.isInterface()) { >+ typeVariable.superclass = superRefType; >+ } else { >+ typeVariable.superInterfaces = new ReferenceBinding[] {superRefType}; >+ } >+ typeVariable.firstBound = superRefType; // first bound used to compute erasure >+ } > } >- typeVariable.firstBound = superRefType; // first bound used to compute erasure > TypeReference[] boundRefs = typeParameter.bounds; > if (boundRefs != null) { >- for (int j = 0, boundLength = boundRefs.length; j < boundLength; j++) { >+ nextBound: for (int j = 0, boundLength = boundRefs.length; j < boundLength; j++) { > typeRef = boundRefs[j]; > superType = this.kind == METHOD_SCOPE > ? typeRef.resolveType((BlockScope)this, false) > : typeRef.resolveType((ClassScope)this); > if (superType == null) { > typeVariable.tagBits |= TagBits.HierarchyHasProblems; >- noProblems = false; >- continue nextVariable; >- } >- typeRef.resolvedType = superType; // hold onto the problem type >- if (isTypeVariableFirstBound && j == 0) { >- problemReporter().noAdditionalBoundAfterTypeVariable(typeRef); >- } >- if (superType.isArrayType()) { >- problemReporter().boundCannotBeArray(typeRef, superType); >- continue nextVariable; >- } >- superRefType = (ReferenceBinding) superType; >- if (!superType.isInterface()) { >- problemReporter().boundMustBeAnInterface(typeRef, superType); >- typeVariable.tagBits |= TagBits.HierarchyHasProblems; >- noProblems = false; >- continue nextVariable; >- } >- // check against superclass >- if (checkForErasedCandidateCollisions && typeVariable.firstBound == typeVariable.superclass) { >- if (hasErasedCandidatesCollisions(superType, typeVariable.superclass, invocations, typeVariable, typeRef)) { >- noProblems = false; >- continue nextVariable; >- } >- } >- // check against superinterfaces >- for (int index = typeVariable.superInterfaces.length; --index >= 0;) { >- ReferenceBinding previousInterface = typeVariable.superInterfaces[index]; >- if (previousInterface == superRefType) { >- problemReporter().duplicateBounds(typeRef, superType); >+ continue nextBound; >+ } else { >+ typeRef.resolvedType = superType; // hold onto the problem type >+ boolean didAlreadyComplain = false; >+ if (isFirstBoundTypeVariable && j == 0) { >+ problemReporter().noAdditionalBoundAfterTypeVariable(typeRef); > typeVariable.tagBits |= TagBits.HierarchyHasProblems; >- noProblems = false; >- continue nextVariable; >+ didAlreadyComplain = true; >+ //continue nextBound; - keep these bounds to minimize secondary errors >+ } else if (superType.isArrayType()) { >+ if (!didAlreadyComplain) { >+ problemReporter().boundCannotBeArray(typeRef, superType); >+ typeVariable.tagBits |= TagBits.HierarchyHasProblems; >+ } >+ continue nextBound; >+ } else { >+ if (!superType.isInterface()) { >+ if (!didAlreadyComplain) { >+ problemReporter().boundMustBeAnInterface(typeRef, superType); >+ typeVariable.tagBits |= TagBits.HierarchyHasProblems; >+ } >+ continue nextBound; >+ } > } >- if (checkForErasedCandidateCollisions) { >- if (hasErasedCandidatesCollisions(superType, previousInterface, invocations, typeVariable, typeRef)) { >- noProblems = false; >- continue nextVariable; >+ // check against superclass >+ if (checkForErasedCandidateCollisions && typeVariable.firstBound == typeVariable.superclass) { >+ if (hasErasedCandidatesCollisions(superType, typeVariable.superclass, invocations, typeVariable, typeRef)) { >+ continue nextBound; >+ } >+ } >+ // check against superinterfaces >+ ReferenceBinding superRefType = (ReferenceBinding) superType; >+ for (int index = typeVariable.superInterfaces.length; --index >= 0;) { >+ ReferenceBinding previousInterface = typeVariable.superInterfaces[index]; >+ if (previousInterface == superRefType) { >+ problemReporter().duplicateBounds(typeRef, superType); >+ typeVariable.tagBits |= TagBits.HierarchyHasProblems; >+ continue nextBound; >+ } >+ if (checkForErasedCandidateCollisions) { >+ if (hasErasedCandidatesCollisions(superType, previousInterface, invocations, typeVariable, typeRef)) { >+ continue nextBound; >+ } > } > } >+ int size = typeVariable.superInterfaces.length; >+ System.arraycopy(typeVariable.superInterfaces, 0, typeVariable.superInterfaces = new ReferenceBinding[size + 1], 0, size); >+ typeVariable.superInterfaces[size] = superRefType; > } >- int size = typeVariable.superInterfaces.length; >- System.arraycopy(typeVariable.superInterfaces, 0, typeVariable.superInterfaces = new ReferenceBinding[size + 1], 0, size); >- typeVariable.superInterfaces[size] = superRefType; > } > } >+ noProblems &= (typeVariable.tagBits & TagBits.HierarchyHasProblems) == 0; > } > return noProblems; > }
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 204536
:
79119
|
79137
| 79165