### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java,v retrieving revision 1.33 diff -u -r1.33 AmbiguousMethodTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java 27 Nov 2006 16:34:12 -0000 1.33 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java 4 Dec 2006 07:19:30 -0000 @@ -799,6 +799,147 @@ "135" ); } + public void test014h() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void x(G x) { System.out.print(true); }\n" + + " void x(F x) { System.out.print(false); }\n" + + " void x2(G x) { System.out.print(true); }\n" + + " void x2(F x) { System.out.print(false); }\n" + + " void a(G x) {}\n" + + " void a(F x) {}\n" + + " void a2(G x) {}\n" + + " void a2(F x) {}\n" + + " void a3(G x) {}\n" + + " > void a3(T x) {}\n" + + " void a4(G x) {}\n" + + " > void a4(S x) {}\n" + + " void a5(T x) {}\n" + + " void a5(F x) {}\n" + + " void b(G x) { System.out.print(true); }\n" + + " void b(F x) { System.out.print(false); }\n" + + " void b2(G x) { System.out.print(true); }\n" + + " void b2(T x) { System.out.print(false); }\n" + + " void b3(G x) { System.out.print(true); }\n" + + " void b3(F x) { System.out.print(false); }\n" + + " > void b4(T x) { System.out.print(true); }\n" + + " void b4(F x) { System.out.print(false); }\n" + + " > void b5(S x) { System.out.print(true); }\n" + + " void b5(F x) { System.out.print(false); }\n" + + " void c(G x) { System.out.print(true); }\n" + + " void c(F x) { System.out.print(false); }\n" + + " public static void main(String[] args) {\n" + + " H h = null;\n" + + " H hraw = null;\n" + + " new X().x(h);\n" + + " new X().x(hraw);\n" + + " new X().x2(h);\n" + + " new X().x2(hraw);\n" + + " new X().b(h);\n" + + " new X().b(hraw);\n" + + " new X().b2(h);\n" + + " new X().b2(hraw);\n" + + " new X().b3(h);\n" + + " new X().b3(hraw);\n" + + " new X().b4(h);\n" + + " new X().b4(hraw);\n" + + " new X().b5(h);\n" + + " new X().b5(hraw);\n" + + " new X().c(h);\n" + + " new X().c(hraw);\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends B {}\n" + + "class F {} \n" + + "class G extends F {}\n" + + "class H extends G {}" + }, + "truetruetruetruetruetruetruetruetruetruetruetruetruetruetruetrue" + ); + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y extends X {\n" + + " public static void ambiguousCases() {\n" + + " H h = null;\n" + + " H hraw = null;\n" + + " new X().a(h);\n" + + " new X().a(hraw);\n" + + " new X().a2(h);\n" + + " new X().a2(hraw);\n" + + " new X().a3(h);\n" + + " new X().a3(hraw);\n" + + " new X().a4(h);\n" + + " new X().a4(hraw);\n" + + " new X().a5(h);\n" + + " new X().a5(hraw);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Y.java (at line 4)\n" + + " H hraw = null;\n" + + " ^\n" + + "H is a raw type. References to generic type H should be parameterized\n" + + "----------\n" + + "2. ERROR in Y.java (at line 5)\n" + + " new X().a(h);\n" + + " ^\n" + + "The method a(G) is ambiguous for the type X\n" + + "----------\n" + + "3. ERROR in Y.java (at line 6)\n" + + " new X().a(hraw);\n" + + " ^\n" + + "The method a(G) is ambiguous for the type X\n" + + "----------\n" + + "4. ERROR in Y.java (at line 7)\n" + + " new X().a2(h);\n" + + " ^^\n" + + "The method a2(G) is ambiguous for the type X\n" + + "----------\n" + + "5. ERROR in Y.java (at line 8)\n" + + " new X().a2(hraw);\n" + + " ^^\n" + + "The method a2(G) is ambiguous for the type X\n" + + "----------\n" + + "6. ERROR in Y.java (at line 9)\n" + + " new X().a3(h);\n" + + " ^^\n" + + "The method a3(G) is ambiguous for the type X\n" + + "----------\n" + + "7. ERROR in Y.java (at line 10)\n" + + " new X().a3(hraw);\n" + + " ^^\n" + + "The method a3(G) is ambiguous for the type X\n" + + "----------\n" + + "8. ERROR in Y.java (at line 11)\n" + + " new X().a4(h);\n" + + " ^^\n" + + "The method a4(G) is ambiguous for the type X\n" + + "----------\n" + + "9. ERROR in Y.java (at line 12)\n" + + " new X().a4(hraw);\n" + + " ^^\n" + + "The method a4(G) is ambiguous for the type X\n" + + "----------\n" + + "10. ERROR in Y.java (at line 13)\n" + + " new X().a5(h);\n" + + " ^^\n" + + "The method a5(H) is ambiguous for the type X\n" + + "----------\n" + + "11. ERROR in Y.java (at line 14)\n" + + " new X().a5(hraw);\n" + + " ^^\n" + + "The method a5(H) is ambiguous for the type X\n" + + "----------\n", + null, + false + ); + } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79798 public void test015() { this.runConformTest( @@ -913,25 +1054,24 @@ public void test018() { this.runConformTest( new String[] { - "X.java", - "public class X {\n" + + "Y.java", + "class X {\n" + " public static X make(Class clazz) {\n" + + " System.out.print(false);\n" + " return new X();\n" + " }\n" + "}\n" + - "class Y extends X {\n" + + "public class Y extends X {\n" + " public static Y make(Class clazz) {\n" + + " System.out.print(true);\n" + " return new Y();\n" + " }\n" + " public static void main(String[] args) throws Exception {\n" + " Y.make(String.class);\n" + " }\n" + - " public static Class getClazz() {\n" + - " return String.class;\n" + - " }\n" + "}" }, - ""); + "true"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647 // in fact, Y make(Class clazz) is the most @@ -939,14 +1079,16 @@ public void test019() { this.runConformTest( new String[] { - "X.java", - "public class X {\n" + + "Y.java", + "class X {\n" + " public static X make(Class clazz) {\n" + + " System.out.print(false);\n" + " return new X();\n" + " }\n" + "}\n" + - "class Y extends X {\n" + + "public class Y extends X {\n" + " public static Y make(Class clazz) {\n" + + " System.out.print(true);\n" + " return new Y();\n" + " }\n" + " public static void main(String[] args) throws Exception {\n" + @@ -957,20 +1099,22 @@ " }\n" + "}" }, - ""); + "true"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647 public void test020() { this.runConformTest( new String[] { - "X.java", - "public class X {\n" + + "Y.java", + "class X {\n" + " public static X make(Class clazz) {\n" + + " System.out.print(true);\n" + " return new X();\n" + " }\n" + "}\n" + - "class Y extends X {\n" + + "public class Y extends X {\n" + " public static Y make(Class clazz) {\n" + + " System.out.print(false);\n" + " return new Y();\n" + " }\n" + " public static void main(String[] args) throws Exception {\n" + @@ -981,21 +1125,23 @@ " }\n" + "}" }, - ""); + "true"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647 // variant: having both methods in the same class should not change anything public void test021() { this.runConformTest( new String[] { - "X.java", - "public class X {\n" + + "Y.java", + "class X {\n" + "}\n" + - "class Y extends X {\n" + + "public class Y extends X {\n" + " public static Y make(Class clazz) {\n" + + " System.out.print(true);\n" + " return new Y();\n" + " }\n" + " public static X make(Class clazz) {\n" + + " System.out.print(false);\n" + " return new X();\n" + " }\n" + " public static void main(String[] args) throws Exception {\n" + @@ -1006,7 +1152,7 @@ " }\n" + "}" }, - ""); + "true"); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647 // variant: using instances triggers raw methods, which are ambiguous @@ -1083,19 +1229,33 @@ "X.java", "import java.util.*;\n" + "public class X {\n" + - " public static void foo(Collection p) {\n" + - " System.out.println(1);\n" + + " public static void staticFoo(Collection p) {\n" + + " System.out.print(1);\n" + " }\n" + - " public static > void foo(T p) {\n" + - " System.out.println(2);\n" + + " public static > void staticFoo(T p) {\n" + + " System.out.print(2);\n" + + " }\n" + + " public void foo(Collection p) {\n" + + " System.out.print(1);\n" + + " }\n" + + " public > void foo(T p) {\n" + + " System.out.print(2);\n" + + " }\n" + + " public void foo2(Collection p) {\n" + + " System.out.print(1);\n" + + " }\n" + + " public void foo2(List p) {\n" + + " System.out.print(2);\n" + " }\n" + " public static void main(String[] args) {\n" + - " foo(new ArrayList(Arrays.asList(\"\")));\n" + + " staticFoo(new ArrayList(Arrays.asList(\"\")));\n" + + " new X().foo(new ArrayList(Arrays.asList(\"\")));\n" + + " new X().foo2(new ArrayList(Arrays.asList(\"\")));\n" + " }\n" + "}" }, - "2"); -} + "222"); +} // https://bugs.eclipse.org/bugs/show_bug.cgi?id=159711 // self contained variant public void test024() { #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java,v retrieving revision 1.88 diff -u -r1.88 ParameterizedTypeBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java 28 Nov 2006 13:40:43 -0000 1.88 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java 4 Dec 2006 07:19:33 -0000 @@ -291,16 +291,6 @@ return nameBuffer.toString(); } -public TypeBinding eliminateTypeVariable(TypeVariableBinding variable) { - if ((this.tagBits & TagBits.HasTypeVariable) == 0) { - return this; - } - if (isReferencing(variable)) { - return new RawTypeBinding(this.type, this.enclosingType, this.environment); - } - return this; -} - /** * @see org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#enclosingType() */ @@ -738,24 +728,6 @@ public boolean isRawSubstitution() { return isRawType(); } - -public boolean isReferencing(TypeVariableBinding variable) { - int argsNb = this.arguments.length; - if ((this.tagBits & TagBits.HasTypeVariable) != 0) { - for (int i = 0; i < argsNb; i++) { - if (this.arguments[i] == variable) { - return true; - } - } - // two separate passes to cut recursion for , W extends J> - for (int i = 0; i < argsNb; i++) { - if (this.arguments[i].isReferencing(variable)) { - return true; - } - } - } - return false; -} /** * @see org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#memberTypes() Index: compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java,v retrieving revision 1.79 diff -u -r1.79 TypeBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java 28 Nov 2006 13:40:43 -0000 1.79 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java 4 Dec 2006 07:19:34 -0000 @@ -133,16 +133,6 @@ return 0; } -/** - * Return this if variable does not participate to its definition, a rawified - * type binding else. - * @param variable the type variable to eliminate - * @return a type binding that does not use variable - */ -public TypeBinding eliminateTypeVariable(TypeVariableBinding variable) { - return this; -} - /* Answer the receiver's enclosing type... null if the receiver is a top level type. */ public ReferenceBinding enclosingType() { @@ -456,16 +446,6 @@ } /** - * Return true iff variable participates to the definition of this, directly or - * indirectly (through type parameters, bounds, etc.). - * @param variable the type variable to search for - * @return true iff variable participates to the definition of this - */ -public boolean isReferencing(TypeVariableBinding variable) { - return false; -} - -/** * Returns true if the type is parameterized, e.g. List */ public boolean isParameterizedType() { Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java,v retrieving revision 1.54 diff -u -r1.54 ParameterizedGenericMethodBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java 27 Nov 2006 16:34:11 -0000 1.54 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java 4 Dec 2006 07:19:32 -0000 @@ -458,13 +458,8 @@ TypeVariableBinding[] originalVariables = originalMethod.typeVariables; int length = originalVariables.length; TypeBinding[] newArguments = new TypeBinding[length]; - boolean isStatic = this.isStatic(); - for (int i = 0; i < length; i++) { - newArguments[i] = isStatic ? - originalVariables[i].semiRawifiedFirstUpperBound() : - // full rawification too much for statics - environment.convertToRawType(originalVariables[i].upperBound()); - } + for (int i = 0; i < length; i++) + newArguments[i] = environment.convertToRawType(originalVariables[i].upperBound()); this.tiebreakMethod = this.environment.createParameterizedGenericMethod(this.originalMethod, newArguments); } return this.tiebreakMethod; Index: compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java,v retrieving revision 1.56 diff -u -r1.56 TypeVariableBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java 28 Nov 2006 13:40:43 -0000 1.56 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java 4 Dec 2006 07:19:34 -0000 @@ -334,21 +334,6 @@ return false; return true; } - -public boolean isReferencing(TypeVariableBinding variable) { - if (this == variable) { - return true; - } - if (this.firstBound.isReferencing(variable)) { - return true; - } - for (int i = 0, l = this.superInterfaces.length ; i < l ; i++) { - if (this.superInterfaces[i].isReferencing(variable)) { - return true; - } - } - return false; -} /** * Returns true if the type was declared as a type variable @@ -412,28 +397,6 @@ return this; } -/** - * Return the first upper bound of this if it does not reference this, else - * elaborate and return a copy of the first upper bound of this where raw types - * replace parameterized types that reference this. - * Examples (in which this is named T): - *
- * T ->>; /java/lang/Object
- * T extends X&I -> X
- * T extends X<String> -> X<String>
- * T extends X<T> -> X#RAW
- * 
- * The result has the property of not relying upon recursion for its definition. - * @return the first upper bound of this if it does not reference this, a - * modified copy of the first upper bound of this else - */ -TypeBinding semiRawifiedFirstUpperBound() { - if (this.firstBound == null) { - return this.superclass; // java/lang/Object - } - return this.firstBound.eliminateTypeVariable(this); -} - /** * @see org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#shortReadableName() */ Index: compiler/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java,v retrieving revision 1.58 diff -u -r1.58 WildcardBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java 28 Nov 2006 13:40:43 -0000 1.58 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java 4 Dec 2006 07:19:34 -0000 @@ -352,13 +352,6 @@ } } -public boolean isReferencing(TypeVariableBinding variable) { - if (this.bound != null) { - return this.bound.isReferencing(variable); - } - return false; -} - /** * @see org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#isSuperclassOf(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) */ 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.294 diff -u -r1.294 Scope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 30 Nov 2006 11:20:43 -0000 1.294 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 4 Dec 2006 07:19:34 -0000 @@ -2496,13 +2496,23 @@ for (int i = 0; i < oneParamsLength; i++) { TypeBinding oneParam = oneParams[i]; TypeBinding twoParam = twoParams[i]; - if (oneParam == twoParam) continue; - if (oneParam.isRawType()) { - TypeBinding match = oneParam.findSuperTypeWithSameErasure(twoParam); - if (match != twoParam) - return false; + if (oneParam == twoParam) { + if (oneParam.leafComponentType().isRawType()) { + // A#RAW is not more specific than a rawified A + if (oneParam == one.original().parameters[i] && oneParam != two.original().parameters[i]) + return false; + } + continue; } - if (!oneParam.isCompatibleWith(twoParam)) { + if (oneParam.isCompatibleWith(twoParam)) { + if (oneParam.leafComponentType().isRawType()) { + if (oneParam.needsUncheckedConversion(twoParam)) + return false; + // A#RAW is not more specific than a rawified A + if (oneParam == one.original().parameters[i] && twoParam != two.original().parameters[i]) + return false; + } + } else { if (i == oneParamsLength - 1 && one.isVarargs() && two.isVarargs()) { TypeBinding eType = ((ArrayBinding) twoParam).elementsType(); if (oneParam == eType || oneParam.isCompatibleWith(eType))