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 64568 Details for
Bug 180789
[1.5][compiler] invalid incompatible return type error
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Fix + test cases
patch.txt (text/plain), 18.57 KB, created by
Maxime Daniel
on 2007-04-23 02:52:37 EDT
(
hide
)
Description:
Fix + test cases
Filename:
MIME Type:
Creator:
Maxime Daniel
Created:
2007-04-23 02:52:37 EDT
Size:
18.57 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java,v >retrieving revision 1.74 >diff -u -r1.74 MethodVerifier15.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java 17 Apr 2007 14:34:08 -0000 1.74 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java 23 Apr 2007 06:50:08 -0000 >@@ -769,6 +769,17 @@ > return copy; > } > boolean reportIncompatibleReturnTypeError(MethodBinding currentMethod, MethodBinding inheritedMethod) { >+ // JLS 3 ยง8.4.5: more are accepted, with an unchecked conversion >+ if (currentMethod.returnType == inheritedMethod.returnType.erasure()) { >+ TypeBinding[] currentParams = currentMethod.parameters; >+ TypeBinding[] inheritedParams = inheritedMethod.parameters; >+ for (int i = 0, l = currentParams.length; i < l; i++) { >+ if (!areTypesEqual(currentParams[i], inheritedParams[i])) { >+ problemReporter(currentMethod).unsafeReturnTypeOverride(currentMethod, inheritedMethod, this.type); >+ return false; >+ } >+ } >+ } > if (currentMethod.typeVariables == Binding.NO_TYPE_VARIABLES > && inheritedMethod.original().typeVariables != Binding.NO_TYPE_VARIABLES > && currentMethod.returnType.erasure().findSuperTypeWithSameErasure(inheritedMethod.returnType.erasure()) != null) { >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java,v >retrieving revision 1.83 >diff -u -r1.83 MethodVerifier.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java 17 Apr 2007 14:34:09 -0000 1.83 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java 23 Apr 2007 06:50:08 -0000 >@@ -627,6 +627,16 @@ > SimpleSet findSuperinterfaceCollisions(ReferenceBinding superclass, ReferenceBinding[] superInterfaces) { > return null; // noop in 1.4 > } >+/** >+ * Return true and report an incompatibleReturnType error if currentMethod's >+ * return type is strictly incompatible with inheritedMethod's, else return >+ * false and report an unchecked conversion warning. Do not call when >+ * areReturnTypesCompatible(currentMethod, inheritedMethod) returns true. >+ * @param currentMethod the (potentially) inheriting method >+ * @param inheritedMethod the inherited method >+ * @return true if currentMethod's return type is strictly incompatible with >+ * inheritedMethod's >+ */ > boolean reportIncompatibleReturnTypeError(MethodBinding currentMethod, MethodBinding inheritedMethod) { > problemReporter(currentMethod).incompatibleReturnType(currentMethod, inheritedMethod); > return true; >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java,v >retrieving revision 1.121 >diff -u -r1.121 MethodVerifyTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java 28 Mar 2007 04:52:16 -0000 1.121 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java 23 Apr 2007 06:50:19 -0000 >@@ -5302,18 +5302,16 @@ > // warning: create() in HashOrder overrides <U>create() in DoubleHash; return type requires unchecked conversion > ); > } >- //https://bugs.eclipse.org/bugs/show_bug.cgi?id=125956 >- public void test081() { >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=125956 >+ public void test081a() { > this.runNegativeTest( > new String[] { > "X.java", > "public abstract class X<U> implements I {\n" + > " public A<String> foo() { return null; }\n" + >- " public <S> A<U> bar() { return null; }\n" + > "}\n" + > "interface I {\n" + > " <T> A<T> foo();\n" + >- " <S> A<S> bar();\n" + > "}\n" + > "class A<V> {}" > }, >@@ -5322,14 +5320,28 @@ > " public A<String> foo() { return null; }\r\n" + > " ^\n" + > "Type safety: The return type A<String> for foo() from the type X<U> needs unchecked conversion to conform to A<Object> from the type I\n" + >+ "----------\n" >+ ); >+ } >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=125956 >+ public void test081b() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public abstract class X<U> implements I {\n" + >+ " public <S> A<U> bar() { return null; }\n" + >+ "}\n" + >+ "interface I {\n" + >+ " <S> A<S> bar();\n" + >+ "}\n" + >+ "class A<V> {}" >+ }, > "----------\n" + >- "2. ERROR in X.java (at line 3)\r\n" + >+ "1. ERROR in X.java (at line 2)\r\n" + > " public <S> A<U> bar() { return null; }\r\n" + > " ^^^^\n" + > "The return type is incompatible with I.bar()\n" + > "----------\n" >- // <S>bar() in X cannot implement <S>bar() in I; attempting to use incompatible return type >- // warning: foo() in X implements <T>foo() in I; return type requires unchecked conversion > ); > } > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=105339 >@@ -7544,4 +7556,368 @@ > "Type safety: The return type Enum<?> for foo() from the type X.B needs unchecked conversion to conform to U from the type X.A<T>\n" + > "----------\n"); > } >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+public void test128() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "interface I<U, V> {\n" + >+ " U foo(Object o, V v);\n" + >+ "}\n" + >+ "public class X<U, V> implements I<U, V> {\n" + >+ " public Object foo(Object o, Object v) {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 5)\n" + >+ " public Object foo(Object o, Object v) {\n" + >+ " ^^^^^^\n" + >+ "Type safety: The return type Object for foo(Object, Object) from the type X<U,V> needs unchecked conversion to conform to U from the type I<U,V>\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+// variant - Object is not a subtype of Z >+public void test129() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "interface I<U, V> {\n" + >+ " U foo(Object o, V v);\n" + >+ "}\n" + >+ "public class X<U extends Z, V> implements I<U, V> {\n" + >+ " public Object foo(Object o, Object v) {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" + >+ "class Z {\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " public Object foo(Object o, Object v) {\n" + >+ " ^^^^^^\n" + >+ "The return type is incompatible with I<U,V>.foo(Object, V)\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+// ** variant - Z<Object> is not a subtype of Z<U>, and |Z<U>| = Z, not Z<Object> >+public void test130() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "interface I<U, V> {\n" + >+ " Z<U> foo(Object o, V v);\n" + >+ "}\n" + >+ "public class X<U, V> implements I<U, V> {\n" + >+ " public Z<Object> foo(Object o, Object v) {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" + >+ "class Z<T> {\n" + >+ "}" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " public Z<Object> foo(Object o, Object v) {\n" + >+ " ^^^^^^^^^\n" + >+ "The return type is incompatible with I<U,V>.foo(Object, V)\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+// variant - two interfaces >+public void test131() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "interface I<U, V> {\n" + >+ " U foo(Object o, V v);\n" + >+ "}\n" + >+ "interface X<U, V> extends I<U, V> {\n" + >+ " Object foo(Object o, Object v);\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 5)\n" + >+ " Object foo(Object o, Object v);\n" + >+ " ^^^^^^\n" + >+ "Type safety: The return type Object for foo(Object, Object) from the type X<U,V> needs unchecked conversion to conform to U from the type I<U,V>\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+// variant - simpler test case >+public void test132() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "interface I<U> {\n" + >+ " U foo();\n" + >+ "}\n" + >+ "public class X<U> implements I<U> {\n" + >+ " public Object foo() {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " public Object foo() {\n" + >+ " ^^^^^^\n" + >+ "The return type is incompatible with I<U>.foo()\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+// variant >+public void test133() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<U extends Z> {\n" + >+ " U foo() {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" + >+ "class Y<U extends Z> extends X<U> {\n" + >+ " public Z foo() {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" + >+ "class Z {\n" + >+ "}" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 7)\n" + >+ " public Z foo() {\n" + >+ " ^\n" + >+ "The return type is incompatible with X<U>.foo()\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 7)\n" + >+ " public Z foo() {\n" + >+ " ^^^^^\n" + >+ "The method foo() of type Y<U> should be tagged with @Override since it actually overrides a superclass method\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+// variant - unchecked conversion of ZC to ZC<String> that is a subtype of Z<String> >+public void test134() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " Z<String> foo() {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" + >+ "class Y extends X {\n" + >+ " public ZC foo() {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" + >+ "class Z<T> {\n" + >+ "}\n" + >+ "class ZC<T> extends Z<T> {\n" + >+ "}" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 7)\n" + >+ " public ZC foo() {\n" + >+ " ^^\n" + >+ "ZC is a raw type. References to generic type ZC<T> should be parameterized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 7)\n" + >+ " public ZC foo() {\n" + >+ " ^^\n" + >+ "Type safety: The return type ZC for foo() from the type Y needs unchecked conversion to conform to Z<String> from the type X\n" + >+ "----------\n" + >+ "3. WARNING in X.java (at line 7)\n" + >+ " public ZC foo() {\n" + >+ " ^^^^^\n" + >+ "The method foo() of type Y should be tagged with @Override since it actually overrides a superclass method\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+// variant - cast is not appropriate >+public void test135() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "interface I<U, V> {\n" + >+ " U foo(Object o, V v);\n" + >+ "}\n" + >+ "interface J<U, V> extends I<U, V> {\n" + >+ " Object foo(Object o, V v);\n" + >+ "}\n" + >+ "class X {\n" + >+ " J<Integer, Integer> m1;\n" + >+ " I<Integer, Integer> m2 = (I<Integer, Integer>) m1;\n" + >+ "}" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " Object foo(Object o, V v);\n" + >+ " ^^^^^^\n" + >+ "The return type is incompatible with I<U,V>.foo(Object, V)\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 9)\n" + >+ " I<Integer, Integer> m2 = (I<Integer, Integer>) m1;\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Unnecessary cast from J<Integer,Integer> to I<Integer,Integer>\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+// variant - type identity vs type equivalence >+public void test136() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "interface I<U> {\n" + >+ " U foo(I<?> p);\n" + >+ "}\n" + >+ "public class X<U> implements I<U> {\n" + >+ " public Object foo(I<? extends Object> p) {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " public Object foo(I<? extends Object> p) {\n" + >+ " ^^^^^^\n" + >+ "The return type is incompatible with I<U>.foo(I<?>)\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+// variant - type identity vs type equivalence >+public void test137() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "interface I<U> {\n" + >+ " U foo(I<? extends Object> p);\n" + >+ "}\n" + >+ "public class X<U> implements I<U> {\n" + >+ " public Object foo(I<?> p) {\n" + >+ " return null;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " public Object foo(I<?> p) {\n" + >+ " ^^^^^^\n" + >+ "The return type is incompatible with I<U>.foo(I<? extends Object>)\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+// variant - @Override annotation >+public void test138() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<U> {\n" + >+ " U foo() { return null; }\n" + >+ "}\n" + >+ "class Y<U> extends X<U> {\n" + >+ " @Override // does not override error\n" + >+ " Object foo() { return null; } // cannot override foo(), incompatible return type error\n" + >+ "}" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 6)\n" + >+ " Object foo() { return null; } // cannot override foo(), incompatible return type error\n" + >+ " ^^^^^^\n" + >+ "The return type is incompatible with X<U>.foo()\n" + >+ "----------\n"); >+}// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+// variant - @Override annotation >+public void test139() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<U> {\n" + >+ " U foo(U one) { return null; }\n" + >+ "}\n" + >+ "class Y<U> extends X<U> {\n" + >+ " @Override\n" + >+ " Object foo(Object one) { return null; } // unchecked conversion warning\n" + >+ "}" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 6)\n" + >+ " Object foo(Object one) { return null; } // unchecked conversion warning\n" + >+ " ^^^^^^\n" + >+ "Type safety: The return type Object for foo(Object) from the type Y<U> needs unchecked conversion to conform to U from the type X<U>\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+// variant - @Override annotation >+public void test140() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<U> {\n" + >+ " U foo(U one, U two) { return null; }\n" + >+ "}\n" + >+ "class Y<U> extends X<U> {\n" + >+ " @Override // does not override error\n" + >+ " Object foo(Object one, U two) { return null; }\n" + >+ "}" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 6)\n" + >+ " Object foo(Object one, U two) { return null; }\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Name clash: The method foo(Object, U) of type Y<U> has the same erasure as foo(U, U) of type X<U> but does not override it\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 6)\n" + >+ " Object foo(Object one, U two) { return null; }\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^\n" + >+ (complianceLevel.compareTo(COMPLIANCE_1_5) <= 0 ? >+ "The method foo(Object, U) of type Y<U> must override a superclass method\n" : >+ "The method foo(Object, U) of type Y<U> must override or implement a supertype method\n") + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+// variant - @Override annotation >+public void test141() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<U> {\n" + >+ " U foo(U one) { return null; }\n" + >+ "}\n" + >+ "class Y<U> extends X<U> {\n" + >+ " @Override // does not override error\n" + >+ " Object foo(U one) { return null; } // cannot override foo(U), incompatible return type error\n" + >+ "}" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 6)\n" + >+ " Object foo(U one) { return null; } // cannot override foo(U), incompatible return type error\n" + >+ " ^^^^^^\n" + >+ "The return type is incompatible with X<U>.foo(U)\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 >+// variant - @Override annotation >+public void test142() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<U> {\n" + >+ " U foo(U one, U two) { return null; }\n" + >+ "}\n" + >+ "class Y<U> extends X<U> {\n" + >+ " @Override // does not override error\n" + >+ " Object foo(U one, U two) { return null; } // cannot override foo(U,U), incompatible return type error\n" + >+ "}" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 6)\n" + >+ " Object foo(U one, U two) { return null; } // cannot override foo(U,U), incompatible return type error\n" + >+ " ^^^^^^\n" + >+ "The return type is incompatible with X<U>.foo(U, U)\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.612 >diff -u -r1.612 GenericTypeTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 20 Apr 2007 23:30:56 -0000 1.612 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java 23 Apr 2007 06:50:17 -0000 >@@ -11175,7 +11175,7 @@ > ^ > */ > } >- public void test0384() { >+ public void test0384a() { > this.runConformTest( > new String[] { > "X.java", >@@ -11191,6 +11191,8 @@ > "}\n" > }, > ""); >+ } >+ public void test0384b() { > this.runNegativeTest( > new String[] { > "X.java", >@@ -11215,7 +11217,6 @@ > "The return type is incompatible with Y.foo2()\n" + > "----------\n"); > } >- > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77496 > public void test0385() { > this.runNegativeTest(
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 180789
:
64144
|
64277
|
64412
|
64486
| 64568