### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java,v retrieving revision 1.336 diff -u -r1.336 ProblemReporter.java --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 10 Jan 2007 17:56:47 -0000 1.336 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 26 Jan 2007 12:10:14 -0000 @@ -2473,6 +2473,33 @@ type.sourceStart(), type.sourceEnd()); } +public void inheritedMethodsHaveIncompatibleReturnTypes(ASTNode location, MethodBinding[] inheritedMethods, int length) { + StringBuffer methodSignatures = new StringBuffer(); + StringBuffer shortSignatures = new StringBuffer(); + for (int i = length; --i >= 0;) { + methodSignatures + .append(inheritedMethods[i].declaringClass.readableName()) + .append('.') + .append(inheritedMethods[i].readableName()); + shortSignatures + .append(inheritedMethods[i].declaringClass.shortReadableName()) + .append('.') + .append(inheritedMethods[i].shortReadableName()); + if (i != 0){ + methodSignatures.append(", "); //$NON-NLS-1$ + shortSignatures.append(", "); //$NON-NLS-1$ + } + } + + this.handle( + // Return type is incompatible with %1 + // 9.4.2 - The return type from the method is incompatible with the declaration. + IProblem.IncompatibleReturnType, + new String[] {methodSignatures.toString()}, + new String[] {shortSignatures.toString()}, + location.sourceStart, + location.sourceEnd); +} public void inheritedMethodsHaveIncompatibleReturnTypes(SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) { StringBuffer methodSignatures = new StringBuffer(); StringBuffer shortSignatures = new StringBuffer(); 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.67 diff -u -r1.67 MethodVerifier15.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java 24 Jan 2007 08:05:56 -0000 1.67 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java 26 Jan 2007 12:10:12 -0000 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; +import org.eclipse.jdt.internal.compiler.ast.TypeParameter; import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; import org.eclipse.jdt.internal.compiler.util.SimpleSet; @@ -447,7 +448,7 @@ } } } -void checkTypeVariableMethods() { +void checkTypeVariableMethods(TypeParameter typeParameter) { char[][] methodSelectors = this.inheritedMethods.keyTable; nextSelector : for (int s = methodSelectors.length; --s >= 0;) { if (methodSelectors[s] == null) continue nextSelector; @@ -477,7 +478,7 @@ int count = index + 1; while (--count > 0 && areReturnTypesEqual(first, matchingInherited[count])){/*empty*/} if (count > 0) { // All inherited methods do NOT have the same vmSignature - problemReporter().inheritedMethodsHaveIncompatibleReturnTypes(this.type, matchingInherited, index + 1); + problemReporter().inheritedMethodsHaveIncompatibleReturnTypes(typeParameter, matchingInherited, index + 1); continue nextSelector; } } @@ -774,7 +775,7 @@ : itsInterfaces[j]; } computeInheritedMethods(superclass, superInterfaces); - checkTypeVariableMethods(); + checkTypeVariableMethods(someType.scope.referenceContext.typeParameters[i]); } } } #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.110 diff -u -r1.110 MethodVerifyTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java 23 Jan 2007 14:37:42 -0000 1.110 +++ src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java 26 Jan 2007 12:10:21 -0000 @@ -2023,7 +2023,7 @@ "----------\n" + "1. ERROR in X.java (at line 3)\r\n" + " public class X {}\r\n" + - " ^\n" + + " ^\n" + "The return type is incompatible with J.foo(), I.foo()\n" + "----------\n" // types J and I are incompatible; both define foo(), but with unrelated return types @@ -2041,7 +2041,7 @@ "----------\n" + "1. ERROR in X.java (at line 2)\r\n" + " class A { public Object foo() { return null; } }public class X {}\r\n" + - " ^\n" + + " ^\n" + "The return type is incompatible with I.foo(), A.foo()\n" + "----------\n" // foo() in A cannot implement foo() in I; attempting to use incompatible return type 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.36 diff -u -r1.36 AmbiguousMethodTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java 24 Jan 2007 08:05:49 -0000 1.36 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java 26 Jan 2007 12:10:19 -0000 @@ -1875,4 +1875,112 @@ }, ""); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590 +// ** +public void test047() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(T t) {\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public int method();\n" + + "}\n" + + "interface J {\n" + + " public boolean method();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^\n" + + "The return type is incompatible with J.method(), I.method()\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590 +// Variant: javac complains as well if we attempt to use method, but noone +// complains upon bar or CONSTANT. +public void test048() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(T t) {\n" + + " t.method();\n" + + " t.bar();\n" + + " if (t.CONSTANT > 0);\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public int method();\n" + + " void bar();\n" + + "}\n" + + "interface J {\n" + + " public boolean method();\n" + + " static final int CONSTANT = 0;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^\n" + + "The return type is incompatible with J.method(), I.method()\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " t.method();\n" + + " ^^^^^^\n" + + "The method method() is ambiguous for the type T\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " if (t.CONSTANT > 0);\n" + + " ^^^^^^^^\n" + + "The static field J.CONSTANT should be accessed in a static way\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590 +// can't implement both interfaces though +public void test049() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " public int method();\n" + + "}\n" + + "interface J {\n" + + " public boolean method();\n" + + "}\n" + + "class X implements I, J {\n" + + " public int method() {\n" + + " return 0;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " public int method() {\n" + + " ^^^\n" + + "The return type is incompatible with J.method()\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590 +// variant: secure the legal case +public void test050() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(T t) {\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public int method();\n" + + "}\n" + + "interface J {\n" + + " public int method();\n" + + "}\n" + }, + ""); +} }