### 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.59 diff -u -r1.59 AmbiguousMethodTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java 8 Jan 2009 21:17:25 -0000 1.59 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java 23 Jan 2009 18:19:19 -0000 @@ -949,6 +949,321 @@ false ); } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=262209 + public void test014i() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {}\n" + + "interface J extends I {}\n" + + "\n" + + "class X {\n" + + " void a(G x) {}\n" + + " > void a(S x) {}\n" + + "\n" + + " void b(G x) {}\n" + + " void b(F x) {}\n" + + "\n" + + " void c(G x) {}\n" + + " void c(F x) {}\n" + + "\n" + + " void d(G x) {}\n" + + " void d(F x) {}\n" + + "\n" + + " void e(G x) {}\n" + + " void e(F x) {}\n" + + "\n" + + " void f(G x) {}\n" + + " void f(S x) {}\n" + + "\n" + + " void g(G x) {}\n" + + " > void g(S x) {}\n" + + "\n" + + " void a2(T x) {}\n" + + " > void a2(S x) {}\n" + + "\n" + + " void b2(T x) {}\n" + + " void b2(F x) {}\n" + + "\n" + + " void c2(T x) {}\n" + + " void c2(F x) {}\n" + + "\n" + + " void d2(T x) {}\n" + + " void d2(F x) {}\n" + + "\n" + + " void e2(T x) {}\n" + + " void e2(F x) {}\n" + + "\n" + + " void f2(T x) {}\n" + + " void f2(S x) {}\n" + + "\n" + + " void g2(T x) {}\n" + + " > void g2(S x) {}\n" + + "\n" + + " void test() {\n" + + " X x = new X();\n" + + " H h = null;\n" + + " H hraw = null;\n" + + "\n" + + " x.a(h);\n" + + " x.a(hraw);\n" + + "\n" + + " x.b(h);\n" + + " x.b(hraw);\n" + + "\n" + + " x.c(h);\n" + + " x.c(hraw);\n" + + "\n" + + " x.d(h);\n" + + " x.d(hraw);\n" + + "\n" + + " x.e(h);\n" + + " x.e(hraw);\n" + + "\n" + + " x.f(h);\n" + + " x.f(hraw);\n" + + "\n" + + " x.g(h);\n" + + " x.g(hraw);\n" + + "\n" + + " x.a2(h);\n" + + " x.a2(hraw);\n" + + "\n" + + " x.b2(h); \n" + + " x.b2(hraw);\n" + + "\n" + + " x.c2(h);\n" + + " x.c2(hraw);\n" + + "\n" + + " x.d2(h);\n" + + " x.d2(hraw);\n" + + "\n" + + " x.e2(h);\n" + + " x.e2(hraw);\n" + + "\n" + + " x.f2(h);\n" + + " x.f2(hraw);\n" + + "\n" + + " x.g2(h); \n" + + " x.g2(hraw);\n" + + " }\n" + + "}\n" + + "\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends B implements I {}\n" + + "class F {} \n" + + "class G extends F implements J {}\n" + + "class H extends G {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void a(G x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " void b(G x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " void b(F x) {}\n" + + " ^\n" + + "F is a raw type. References to generic type F should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 11)\n" + + " void c(G x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 14)\n" + + " void d(G x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 17)\n" + + " void e(G x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 20)\n" + + " void f(G x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 21)\n" + + " void f(S x) {}\n" + + " ^\n" + + "F is a raw type. References to generic type F should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 23)\n" + + " void g(G x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "10. WARNING in X.java (at line 24)\n" + + " > void g(S x) {}\n" + + " ^\n" + + "F is a raw type. References to generic type F should be parameterized\n" + + "----------\n" + + "11. WARNING in X.java (at line 26)\n" + + " void a2(T x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "12. WARNING in X.java (at line 29)\n" + + " void b2(T x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "13. WARNING in X.java (at line 30)\n" + + " void b2(F x) {}\n" + + " ^\n" + + "F is a raw type. References to generic type F should be parameterized\n" + + "----------\n" + + "14. WARNING in X.java (at line 32)\n" + + " void c2(T x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "15. WARNING in X.java (at line 35)\n" + + " void d2(T x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "16. WARNING in X.java (at line 38)\n" + + " void e2(T x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "17. WARNING in X.java (at line 41)\n" + + " void f2(T x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "18. WARNING in X.java (at line 42)\n" + + " void f2(S x) {}\n" + + " ^\n" + + "F is a raw type. References to generic type F should be parameterized\n" + + "----------\n" + + "19. WARNING in X.java (at line 42)\n" + + " void f2(S x) {}\n" + + " ^\n" + + "J is a raw type. References to generic type J should be parameterized\n" + + "----------\n" + + "20. WARNING in X.java (at line 44)\n" + + " void g2(T x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "21. WARNING in X.java (at line 45)\n" + + " > void g2(S x) {}\n" + + " ^\n" + + "F is a raw type. References to generic type F should be parameterized\n" + + "----------\n" + + "22. WARNING in X.java (at line 50)\n" + + " H hraw = null;\n" + + " ^\n" + + "H is a raw type. References to generic type H should be parameterized\n" + + "----------\n" + + "23. ERROR in X.java (at line 52)\n" + + " x.a(h);\n" + + " ^\n" + + "The method a(G) is ambiguous for the type X\n" + + "----------\n" + + "24. ERROR in X.java (at line 53)\n" + + " x.a(hraw);\n" + + " ^\n" + + "The method a(G) is ambiguous for the type X\n" + + "----------\n" + + "25. ERROR in X.java (at line 58)\n" + + " x.c(h);\n" + + " ^\n" + + "The method c(G) is ambiguous for the type X\n" + + "----------\n" + + "26. ERROR in X.java (at line 59)\n" + + " x.c(hraw);\n" + + " ^\n" + + "The method c(G) is ambiguous for the type X\n" + + "----------\n" + + "27. ERROR in X.java (at line 61)\n" + + " x.d(h);\n" + + " ^\n" + + "The method d(G) is ambiguous for the type X\n" + + "----------\n" + + "28. ERROR in X.java (at line 62)\n" + + " x.d(hraw);\n" + + " ^\n" + + "The method d(G) is ambiguous for the type X\n" + + "----------\n" + + "29. ERROR in X.java (at line 64)\n" + + " x.e(h);\n" + + " ^\n" + + "The method e(G) is ambiguous for the type X\n" + + "----------\n" + + "30. ERROR in X.java (at line 65)\n" + + " x.e(hraw);\n" + + " ^\n" + + "The method e(G) is ambiguous for the type X\n" + + "----------\n" + + "31. ERROR in X.java (at line 71)\n" + + " x.g(hraw);\n" + + " ^\n" + + "The method g(G) is ambiguous for the type X\n" + + "----------\n" + + "32. ERROR in X.java (at line 73)\n" + + " x.a2(h);\n" + + " ^^\n" + + "The method a2(H) is ambiguous for the type X\n" + + "----------\n" + + "33. ERROR in X.java (at line 74)\n" + + " x.a2(hraw);\n" + + " ^^\n" + + "The method a2(H) is ambiguous for the type X\n" + + "----------\n" + + "34. ERROR in X.java (at line 79)\n" + + " x.c2(h);\n" + + " ^^\n" + + "The method c2(H) is ambiguous for the type X\n" + + "----------\n" + + "35. ERROR in X.java (at line 80)\n" + + " x.c2(hraw);\n" + + " ^^\n" + + "The method c2(H) is ambiguous for the type X\n" + + "----------\n" + + "36. ERROR in X.java (at line 82)\n" + + " x.d2(h);\n" + + " ^^\n" + + "The method d2(H) is ambiguous for the type X\n" + + "----------\n" + + "37. ERROR in X.java (at line 83)\n" + + " x.d2(hraw);\n" + + " ^^\n" + + "The method d2(H) is ambiguous for the type X\n" + + "----------\n" + + "38. ERROR in X.java (at line 85)\n" + + " x.e2(h);\n" + + " ^^\n" + + "The method e2(H) is ambiguous for the type X\n" + + "----------\n" + + "39. ERROR in X.java (at line 86)\n" + + " x.e2(hraw);\n" + + " ^^\n" + + "The method e2(H) is ambiguous for the type X\n" + + "----------\n" + + "40. ERROR in X.java (at line 92)\n" + + " x.g2(hraw);\n" + + " ^^\n" + + "The method g2(H) is ambiguous for the type X\n" + + "----------\n" + + "41. WARNING in X.java (at line 98)\n" + + " class C extends B implements I {}\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + ); + } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79798 public void test015() { this.runConformTest( #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java,v retrieving revision 1.112 diff -u -r1.112 MethodBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java 5 Dec 2008 12:41:29 -0000 1.112 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java 23 Jan 2009 18:19:19 -0000 @@ -148,6 +148,29 @@ return false; return true; } +MethodBinding asRawMethod(LookupEnvironment env) { + if (this.typeVariables == Binding.NO_TYPE_VARIABLES) return this; + + // substitute type arguments with raw types + int length = this.typeVariables.length; + TypeBinding[] arguments = new TypeBinding[length]; + for (int i = 0; i < length; i++) { + TypeVariableBinding var = this.typeVariables[i]; + if (var.boundsCount() <= 1) { + arguments[i] = env.convertToRawType(var.upperBound(), false /*do not force conversion of enclosing types*/); + } else { + // use an intersection type to retain full bound information if more than 1 bound + TypeBinding rawSuperclass = env.convertToRawType(var.superclass(), false); + TypeBinding[] itsSuperinterfaces = var.superInterfaces(); + int superLength = itsSuperinterfaces.length; + TypeBinding[] rawSuperinterfaces = new TypeBinding[superLength]; + for (int s = 0; s < superLength; s++) + rawSuperinterfaces[s] = env.convertToRawType(itsSuperinterfaces[s], false); + arguments[i] = env.createWildcard(null, 0, rawSuperclass, rawSuperinterfaces, org.eclipse.jdt.internal.compiler.ast.Wildcard.EXTENDS); + } + } + return env.createParameterizedGenericMethod(this, arguments); +} /* Answer true if the receiver is visible to the type provided by the scope. * InvocationSite implements isSuperAccess() to provide additional information * if the receiver is protected. 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.66 diff -u -r1.66 ParameterizedGenericMethodBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java 8 Jan 2009 20:51:04 -0000 1.66 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java 23 Jan 2009 18:19:19 -0000 @@ -11,7 +11,6 @@ package org.eclipse.jdt.internal.compiler.lookup; import org.eclipse.jdt.internal.compiler.ast.MessageSend; -import org.eclipse.jdt.internal.compiler.ast.Wildcard; /** * Binding denoting a generic method after type parameter substitutions got performed. @@ -485,22 +484,8 @@ * @see org.eclipse.jdt.internal.compiler.lookup.MethodBinding#tiebreakMethod() */ public MethodBinding tiebreakMethod() { - if (this.tiebreakMethod == null) { - TypeVariableBinding[] originalVariables = this.originalMethod.typeVariables; - int length = originalVariables.length; - TypeBinding[] newArguments = new TypeBinding[length]; - for (int i = 0; i < length; i++) { - TypeVariableBinding originalVariable = originalVariables[i]; - if (originalVariable.boundsCount() <= 1) { - newArguments[i] = this.environment.convertToRawType(originalVariable.upperBound(), false /*do not force conversion of enclosing types*/); - } else { - newArguments[i] = this.environment.convertToRawType( - // use an intersection type to retain full bound information - this.environment.createWildcard(null, 0, originalVariable.superclass(), originalVariable.superInterfaces(), Wildcard.EXTENDS), false /*do not force conversion of enclosing types*/); - } - } - this.tiebreakMethod = this.environment.createParameterizedGenericMethod(this.originalMethod, newArguments); - } + if (this.tiebreakMethod == null) + this.tiebreakMethod = this.originalMethod.asRawMethod(this.environment); return this.tiebreakMethod; } -} +} \ No newline at end of file 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.70 diff -u -r1.70 TypeVariableBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java 8 Jan 2009 20:51:04 -0000 1.70 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java 23 Jan 2009 18:19:19 -0000 @@ -290,6 +290,17 @@ return this.genericTypeSignature = CharOperation.concat('T', this.sourceName, ';'); } + boolean hasOnlyRawBounds() { + if (this.superclass != null && !this.superclass.isRawType()) + return false; + + if (this.superInterfaces != null) + for (int i = 0, l = this.superInterfaces.length; i < l; i++) + if (!this.superInterfaces[i].isRawType()) + return false; + + return true; + } /** * Returns true if the type variable is directly bound to a given type */ 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.348 diff -u -r1.348 Scope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 12 Jan 2009 18:37:16 -0000 1.348 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 23 Jan 2009 18:19:19 -0000 @@ -2778,36 +2778,36 @@ int oneParamsLength = oneParams.length; int twoParamsLength = twoParams.length; if (oneParamsLength == twoParamsLength) { - for (int i = 0; i < oneParamsLength; i++) { + next : for (int i = 0; i < oneParamsLength; i++) { TypeBinding oneParam = oneParams[i]; TypeBinding twoParam = twoParams[i]; - if (oneParam == twoParam) { - if (twoParam.leafComponentType().isRawType()) { - // must detect & reject this case - // when Y extends X - // void foo(Y y) {} - // > void foo(T t) {} - // foo(T) will show up as foo(Y#RAW) and not foo(X#RAW) - // Y#RAW is not more specific than a rawified X - TypeBinding originalOneParam = one.original().parameters[i].leafComponentType(); - if ((originalOneParam.isTypeVariable() ? ((TypeVariableBinding) originalOneParam).upperBound() - : originalOneParam).isRawType()) - if (twoParam.leafComponentType().erasure() != two.original().parameters[i] - .leafComponentType().erasure()) - return false; - } - } else if (oneParam.isCompatibleWith(twoParam)) { - if (oneParam.leafComponentType().isRawType()) { - if (oneParam.needsUncheckedConversion(twoParam)) - if (oneParam.leafComponentType().erasure() != twoParam.leafComponentType().erasure()) - return false; + if (oneParam == twoParam || oneParam.isCompatibleWith(twoParam)) { + if (two.declaringClass.isRawType()) continue next; + + TypeBinding originalOneParam = one.original().parameters[i].leafComponentType(); + switch (originalOneParam.kind()) { + case Binding.TYPE_PARAMETER : + if (!((TypeVariableBinding) originalOneParam).upperBound().isRawType()) break; + //$FALL-THROUGH$ + case Binding.RAW_TYPE: + // originalOneParam is RAW so it cannot be more specific than a wildcard or parameterized type + TypeBinding originalTwoParam = two.original().parameters[i].leafComponentType(); + switch (originalTwoParam.kind()) { + case Binding.TYPE_PARAMETER : + if (((TypeVariableBinding) originalTwoParam).hasOnlyRawBounds()) + continue next; + return false; + case Binding.WILDCARD_TYPE : + case Binding.INTERSECTION_TYPE: + case Binding.PARAMETERIZED_TYPE : + return false; + } } } else { if (i == oneParamsLength - 1 && one.isVarargs() && two.isVarargs()) { TypeBinding eType = ((ArrayBinding) twoParam).elementsType(); if (oneParam == eType || oneParam.isCompatibleWith(eType)) - return true; // special case to choose between 2 varargs methods when the last arg is - // Object[] + return true; // special case to choose between 2 varargs methods when the last arg is Object[] } return false; } @@ -2817,8 +2817,7 @@ if (one.isVarargs() && two.isVarargs()) { if (oneParamsLength > twoParamsLength) { - // special case when autoboxing makes (int, int...) better than (Object...) but not (int...) or - // (Integer, int...) + // special case when autoboxing makes (int, int...) better than (Object...) but not (int...) or (Integer, int...) if (((ArrayBinding) twoParams[twoParamsLength - 1]).elementsType().id != TypeIds.T_JavaLangObject) return false; } 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.71 diff -u -r1.71 WildcardBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java 22 Jan 2009 11:22:54 -0000 1.71 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java 23 Jan 2009 18:19:19 -0000 @@ -68,12 +68,12 @@ case Wildcard.UNBOUND : return true; case Wildcard.EXTENDS : - if (argumentType.isCompatibleWith(this.bound)) return true; + if (!argumentType.isCompatibleWith(this.bound)) return false; // check other bounds (lub scenario) for (int i = 0, length = this.otherBounds == null ? 0 : this.otherBounds.length; i < length; i++) { - if (argumentType.isCompatibleWith(this.otherBounds[i])) return true; + if (!argumentType.isCompatibleWith(this.otherBounds[i])) return false; } - return false; + return true; default: // SUPER // ? super Exception ok for: IOException, since it would be ok for (Exception)ioException return argumentType.isCompatibleWith(this.bound);