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 69682 Details for
Bug 189933
[compiler][1.5] extraneous ambiguous constructor error on generics
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Discussion basis (a prototype that works, plus split test cases)
patch189933_03.txt (text/plain), 17.83 KB, created by
Maxime Daniel
on 2007-06-01 08:07:16 EDT
(
hide
)
Description:
Discussion basis (a prototype that works, plus split test cases)
Filename:
MIME Type:
Creator:
Maxime Daniel
Created:
2007-06-01 08:07:16 EDT
Size:
17.83 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >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.309 >diff -u -r1.309 Scope.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 24 May 2007 14:29:32 -0000 1.309 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 1 Jun 2007 11:59:01 -0000 >@@ -724,7 +724,7 @@ > } > // no need to check for visibility - interface methods are public > if (compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) >- return mostSpecificMethodBinding(candidates, candidatesCount, argumentTypes, invocationSite, receiverType); >+ return mostSpecificMethodBinding(candidates, null, candidatesCount, argumentTypes, invocationSite, receiverType); > return mostSpecificInterfaceMethodBinding(candidates, candidatesCount, invocationSite); > } > >@@ -1112,6 +1112,7 @@ > // if found several candidates, then eliminate those not matching argument types > int foundSize = found.size; > MethodBinding[] candidates = null; >+ boolean[] differingCandidates = null; > int candidatesCount = 0; > MethodBinding problemMethod = null; > boolean searchForDefaultAbstractMethod = isCompliant14 && ! receiverTypeIsInterface && (receiverType.isAbstract() || receiverType.isTypeVariable()); >@@ -1129,8 +1130,13 @@ > unitScope.recordTypeReferences(compatibleMethod.thrownExceptions); > return compatibleMethod; > } >- if (candidatesCount == 0) >+ if (candidatesCount == 0) { > candidates = new MethodBinding[foundSize]; >+ differingCandidates = new boolean[foundSize]; >+ } >+ if (compatibleMethod != methodBinding) { >+ differingCandidates[candidatesCount] = true; >+ } > candidates[candidatesCount++] = compatibleMethod; > } else if (problemMethod == null) { > problemMethod = compatibleMethod; >@@ -1205,6 +1211,7 @@ > if (visiblesCount != i) { > candidates[i] = null; > candidates[visiblesCount] = methodBinding; >+ differingCandidates[visiblesCount] = differingCandidates[i]; > } > visiblesCount++; > } >@@ -1243,7 +1250,7 @@ > } > } > >- MethodBinding mostSpecificMethod = mostSpecificMethodBinding(candidates, visiblesCount, argumentTypes, invocationSite, receiverType); >+ MethodBinding mostSpecificMethod = mostSpecificMethodBinding(candidates, differingCandidates, visiblesCount, argumentTypes, invocationSite, receiverType); > if (searchForDefaultAbstractMethod) { // search interfaces for a better match > if (mostSpecificMethod.isValidBinding()) > // see if there is a better match in the interfaces - see AutoBoxingTest 99, LookupTest#81 >@@ -1670,7 +1677,7 @@ > compatible[0].parameters, > ProblemReasons.NotVisible); > // all of visible are from the same declaringClass, even before 1.4 we can call this method instead of mostSpecificClassMethodBinding >- return mostSpecificMethodBinding(visible, visibleIndex, argumentTypes, invocationSite, receiverType); >+ return mostSpecificMethodBinding(visible, null, visibleIndex, argumentTypes, invocationSite, receiverType); > } catch (AbortCompilation e) { > e.updateContext(invocationSite, referenceCompilationUnit().compilationResult); > throw e; >@@ -1949,7 +1956,7 @@ > if (visible != null) { > MethodBinding[] temp = new MethodBinding[visible.size]; > visible.copyInto(temp); >- foundMethod = mostSpecificMethodBinding(temp, temp.length, argumentTypes, invocationSite, null); >+ foundMethod = mostSpecificMethodBinding(temp, null, temp.length, argumentTypes, invocationSite, null); > } > } > } >@@ -2561,7 +2568,7 @@ > return null; > } > >- protected boolean isAcceptableMethod(MethodBinding one, MethodBinding two) { >+ protected boolean isAcceptableMethod(MethodBinding one, MethodBinding two, boolean twoIsRawified) { > TypeBinding[] oneParams = one.parameters; > TypeBinding[] twoParams = two.parameters; > int oneParamsLength = oneParams.length; >@@ -2581,7 +2588,7 @@ > if (oneParam.isCompatibleWith(twoParam)) { > if (oneParam.leafComponentType().isRawType()) { > // A#RAW is not more specific than a rawified A<T> >- if (oneParam.needsUncheckedConversion(two.original().parameters[i])) >+ if ((twoIsRawified || ! two.parameters[i].isRawType()) && oneParam.needsUncheckedConversion(two.original().parameters[i])) > return false; > } > } else { >@@ -3287,7 +3294,7 @@ > } > > // caveat: this is not a direct implementation of JLS >- protected final MethodBinding mostSpecificMethodBinding(MethodBinding[] visible, int visibleSize, TypeBinding[] argumentTypes, InvocationSite invocationSite, ReferenceBinding receiverType) { >+ protected final MethodBinding mostSpecificMethodBinding(MethodBinding[] visible, boolean differing[], int visibleSize, TypeBinding[] argumentTypes, InvocationSite invocationSite, ReferenceBinding receiverType) { > int[] compatibilityLevels = new int[visibleSize]; > for (int i = 0; i < visibleSize; i++) > compatibilityLevels[i] = parameterCompatibilityLevel(visible[i], argumentTypes); >@@ -3330,7 +3337,10 @@ > */ > if (acceptable == null || !acceptable.isValidBinding()) > continue nextVisible; >- if (!isAcceptableMethod(tiebreakMethod, acceptable)) >+ if (!isAcceptableMethod(tiebreakMethod, acceptable, >+ (differing != null && differing[j]) || >+ /* not enough to replace the differing mechanism: (acceptable instanceof ParameterizedGenericMethodBinding && ((ParameterizedGenericMethodBinding) acceptable).wasInferred) || */ >+ acceptable != methodToTest)) > continue nextVisible; > // pick a concrete method over a bridge method when parameters are equal since the return type of the concrete method is more specific > if (current.isBridge() && !next.isBridge()) >#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.46 >diff -u -r1.46 AmbiguousMethodTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java 30 May 2007 14:55:43 -0000 1.46 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java 1 Jun 2007 11:59:04 -0000 >@@ -799,7 +799,7 @@ > "135" > ); > } >- public void test014h() { >+ public void test014h1() { > this.runConformTest( > new String[] { > "X.java", >@@ -816,8 +816,6 @@ > " <T extends F<C>> void a3(T x) {}\n" + > " void a4(G x) {}\n" + > " <T extends C, S extends F<T>> void a4(S x) {}\n" + >- " <T extends G> void a5(T x) {}\n" + >- " void a5(F<C> x) {}\n" + > " void b(G<C> x) { System.out.print(true); }\n" + > " void b(F x) { System.out.print(false); }\n" + > " void b2(G<C> x) { System.out.print(true); }\n" + >@@ -860,85 +858,268 @@ > }, > "truetruetruetruetruetruetruetruetruetruetruetruetruetruetruetrue" > ); >+ } >+ public void test014h2() { > this.runNegativeTest( > new String[] { >- "Y.java", >- "public class Y extends X {\n" + >+ "X.java", >+ "public class X {\n" + >+ " void a(G x) {}\n" + >+ " void a(F<C> x) {}\n" + >+ "}\n" + >+ "class A {}\n" + >+ "class B extends A {}\n" + >+ "class C extends B {}\n" + >+ "class F<T1> {} \n" + >+ "class G<T2> extends F<T2> {}\n" + >+ "class H<T3> extends G<T3> {}" + >+ "class Y extends X {\n" + > " public static void ambiguousCases() {\n" + > " H<C> 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" + >+ "1. WARNING in X.java (at line 2)\n" + >+ " void a(G x) {}\n" + >+ " ^\n" + >+ "G is a raw type. References to generic type G<T2> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 13)\n" + > " H hraw = null;\n" + > " ^\n" + > "H is a raw type. References to generic type H<T3> should be parameterized\n" + > "----------\n" + >- "2. ERROR in Y.java (at line 5)\n" + >+ "3. ERROR in X.java (at line 14)\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" + >+ "4. ERROR in X.java (at line 15)\n" + > " new X().a(hraw);\n" + > " ^\n" + > "The method a(G) is ambiguous for the type X\n" + >+ "----------\n", >+ null, >+ false >+ ); >+ } >+ public void test014h3() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void a2(G x) {}\n" + >+ " <T extends C> void a2(F<T> x) {}\n" + >+ "}\n" + >+ "class A {}\n" + >+ "class B extends A {}\n" + >+ "class C extends B {}\n" + >+ "class F<T1> {} \n" + >+ "class G<T2> extends F<T2> {}\n" + >+ "class H<T3> extends G<T3> {}" + >+ "class Y extends X {\n" + >+ " public static void ambiguousCases() {\n" + >+ " H<C> h = null;\n" + >+ " new X().a2(h);\n" + >+ " }\n" + >+ "}\n" >+ }, > "----------\n" + >- "4. ERROR in Y.java (at line 7)\n" + >+ "1. WARNING in X.java (at line 2)\n" + >+ " void a2(G x) {}\n" + >+ " ^\n" + >+ "G is a raw type. References to generic type G<T2> should be parameterized\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 13)\n" + > " new X().a2(h);\n" + > " ^^\n" + > "The method a2(G) is ambiguous for the type X\n" + >+ "----------\n" >+ ); >+ } >+ public void test014h4() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void a2(G x) {}\n" + >+ " <T extends C> void a2(F<T> x) {}\n" + >+ "}\n" + >+ "class A {}\n" + >+ "class B extends A {}\n" + >+ "class C extends B {}\n" + >+ "class F<T1> {} \n" + >+ "class G<T2> extends F<T2> {}\n" + >+ "class H<T3> extends G<T3> {}" + >+ "class Y extends X {\n" + >+ " public static void ambiguousCases() {\n" + >+ " H hraw = null;\n" + >+ " new X().a2(hraw);\n" + >+ " }\n" + >+ "}\n" >+ }, > "----------\n" + >- "5. ERROR in Y.java (at line 8)\n" + >+ "1. WARNING in X.java (at line 2)\n" + >+ " void a2(G x) {}\n" + >+ " ^\n" + >+ "G is a raw type. References to generic type G<T2> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 12)\n" + >+ " H hraw = null;\n" + >+ " ^\n" + >+ "H is a raw type. References to generic type H<T3> should be parameterized\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 13)\n" + > " new X().a2(hraw);\n" + > " ^^\n" + > "The method a2(G) is ambiguous for the type X\n" + >+ "----------\n" >+ ); >+ } >+ public void test014h5() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void a3(G x) {}\n" + >+ " <T extends F<C>> void a3(T x) {}\n" + >+ "}\n" + >+ "class A {}\n" + >+ "class B extends A {}\n" + >+ "class C extends B {}\n" + >+ "class F<T1> {} \n" + >+ "class G<T2> extends F<T2> {}\n" + >+ "class H<T3> extends G<T3> {}" + >+ "class Y extends X {\n" + >+ " public static void ambiguousCases() {\n" + >+ " H<C> h = null;\n" + >+ " H hraw = null;\n" + >+ " new X().a3(h);\n" + >+ " new X().a3(hraw);\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 2)\n" + >+ " void a3(G x) {}\n" + >+ " ^\n" + >+ "G is a raw type. References to generic type G<T2> should be parameterized\n" + > "----------\n" + >- "6. ERROR in Y.java (at line 9)\n" + >+ "2. WARNING in X.java (at line 13)\n" + >+ " H hraw = null;\n" + >+ " ^\n" + >+ "H is a raw type. References to generic type H<T3> should be parameterized\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 14)\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" + >+ "4. ERROR in X.java (at line 15)\n" + > " new X().a3(hraw);\n" + > " ^^\n" + > "The method a3(G) is ambiguous for the type X\n" + >+ "----------\n", >+ null, >+ false >+ ); >+ } >+ public void test014h6() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void a4(G x) {}\n" + >+ " <T extends C, S extends F<T>> void a4(S x) {}\n" + >+ "}\n" + >+ "class A {}\n" + >+ "class B extends A {}\n" + >+ "class C extends B {}\n" + >+ "class F<T1> {} \n" + >+ "class G<T2> extends F<T2> {}\n" + >+ "class H<T3> extends G<T3> {}" + >+ "class Y extends X {\n" + >+ " public static void ambiguousCases() {\n" + >+ " H<C> h = null;\n" + >+ " H hraw = null;\n" + >+ " new X().a4(h);\n" + >+ " new X().a4(hraw);\n" + >+ " }\n" + >+ "}\n" >+ }, > "----------\n" + >- "8. ERROR in Y.java (at line 11)\n" + >+ "1. WARNING in X.java (at line 2)\n" + >+ " void a4(G x) {}\n" + >+ " ^\n" + >+ "G is a raw type. References to generic type G<T2> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 13)\n" + >+ " H hraw = null;\n" + >+ " ^\n" + >+ "H is a raw type. References to generic type H<T3> should be parameterized\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 14)\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" + >+ "4. ERROR in X.java (at line 15)\n" + > " new X().a4(hraw);\n" + > " ^^\n" + > "The method a4(G) is ambiguous for the type X\n" + >+ "----------\n", >+ null, >+ false >+ ); >+ } >+ public void test014h7() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " <T extends G> void a5(T x) {}\n" + >+ " void a5(F<C> x) {}\n" + >+ "}\n" + >+ "class A {}\n" + >+ "class B extends A {}\n" + >+ "class C extends B {}\n" + >+ "class F<T1> {} \n" + >+ "class G<T2> extends F<T2> {}\n" + >+ "class H<T3> extends G<T3> {}" + >+ "class Y extends X {\n" + >+ " public static void ambiguousCases() {\n" + >+ " H<C> h = null;\n" + >+ " H hraw = null;\n" + >+ " new X().a5(h);\n" + >+ " new X().a5(hraw);\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 2)\n" + >+ " <T extends G> void a5(T x) {}\n" + >+ " ^\n" + >+ "G is a raw type. References to generic type G<T2> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 13)\n" + >+ " H hraw = null;\n" + >+ " ^\n" + >+ "H is a raw type. References to generic type H<T3> should be parameterized\n" + > "----------\n" + >- "10. ERROR in Y.java (at line 13)\n" + >+ "3. ERROR in X.java (at line 14)\n" + > " new X().a5(h);\n" + > " ^^\n" + > "The method a5(H<C>) is ambiguous for the type X\n" + > "----------\n" + >- "11. ERROR in Y.java (at line 14)\n" + >+ "4. ERROR in X.java (at line 15)\n" + > " new X().a5(hraw);\n" + > " ^^\n" + > "The method a5(H) is ambiguous for the type X\n" + >- "----------\n", >- null, >- false >- ); >+ "----------\n"); > } > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79798 > public void test015() { >@@ -2091,7 +2272,7 @@ > ); > } > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=189933 >-public void _test060() { >+public void test060() { > this.runConformTest( > new String[] { > "X.java", >@@ -2120,7 +2301,7 @@ > } > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=189933 > // variant >-public void _test061() { >+public void test061() { > this.runNegativeTest( > new String[] { > "X.java", >@@ -2177,4 +2358,60 @@ > "----------\n" > ); > } >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=189933 >+// variant >+public void test062() { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X<T> {\n" + >+ " public void bar(K<T, Object> p) {\n" + >+ " new Y<T, Object>(p);\n" + >+ " new Y<T, Object>((J<T, Object>) p);\n" + >+ " }\n" + >+ "}\n" + >+ "class Y<T, U> {\n" + >+ " Y(I<? extends T, ? extends U> p) {\n" + >+ " }\n" + >+ " Y(J<T, ? extends U> p) {\n" + >+ " }\n" + >+ "}\n" + >+ "interface I<T, U> { \n" + >+ "}\n" + >+ "interface J<T, U> extends I<T, U> {\n" + >+ "}\n" + >+ "interface K<T, U> extends I<T, U>, J<T, U> {\n" + >+ "}" >+ }, >+ "" >+ ); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=189933 >+// variant >+public void test063() { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X<T, U> {\n" + >+ " public void bar(K<T, U> p) {\n" + >+ " new Y<T, U>(p);\n" + >+ " new Y<T, U>((J<T, U>) p);\n" + >+ " }\n" + >+ "}\n" + >+ "class Y<T, U> {\n" + >+ " Y(I<? extends T, ? extends U> p) {\n" + >+ " }\n" + >+ " Y(J<T, ? extends U> p) {\n" + >+ " }\n" + >+ "}\n" + >+ "interface I<T, U> { \n" + >+ "}\n" + >+ "interface J<T, U> extends I<T, U> {\n" + >+ "}\n" + >+ "interface K<T, U> extends I<T, U>, J<T, U> {\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 189933
:
69682
|
70019
|
70140
|
70148