View | Details | Raw Unified | Return to bug 163590
Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (+27 lines)
Lines 2473-2478 Link Here
2473
		type.sourceStart(),
2473
		type.sourceStart(),
2474
		type.sourceEnd());
2474
		type.sourceEnd());
2475
}
2475
}
2476
public void inheritedMethodsHaveIncompatibleReturnTypes(ASTNode location, MethodBinding[] inheritedMethods, int length) {
2477
	StringBuffer methodSignatures = new StringBuffer();
2478
	StringBuffer shortSignatures = new StringBuffer();
2479
	for (int i = length; --i >= 0;) {
2480
		methodSignatures
2481
			.append(inheritedMethods[i].declaringClass.readableName())
2482
			.append('.')
2483
			.append(inheritedMethods[i].readableName());
2484
		shortSignatures
2485
			.append(inheritedMethods[i].declaringClass.shortReadableName())
2486
			.append('.')
2487
			.append(inheritedMethods[i].shortReadableName());
2488
		if (i != 0){
2489
			methodSignatures.append(", "); //$NON-NLS-1$
2490
			shortSignatures.append(", "); //$NON-NLS-1$
2491
		}
2492
	}
2493
2494
	this.handle(
2495
		// Return type is incompatible with %1
2496
		// 9.4.2 - The return type from the method is incompatible with the declaration.
2497
		IProblem.IncompatibleReturnType,
2498
		new String[] {methodSignatures.toString()},
2499
		new String[] {shortSignatures.toString()},
2500
		location.sourceStart,
2501
		location.sourceEnd);
2502
}
2476
public void inheritedMethodsHaveIncompatibleReturnTypes(SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
2503
public void inheritedMethodsHaveIncompatibleReturnTypes(SourceTypeBinding type, MethodBinding[] inheritedMethods, int length) {
2477
	StringBuffer methodSignatures = new StringBuffer();
2504
	StringBuffer methodSignatures = new StringBuffer();
2478
	StringBuffer shortSignatures = new StringBuffer();
2505
	StringBuffer shortSignatures = new StringBuffer();
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java (-3 / +4 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
11
package org.eclipse.jdt.internal.compiler.lookup;
12
12
13
import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
13
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
14
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
14
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
15
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
15
16
Lines 447-453 Link Here
447
		}
448
		}
448
	}
449
	}
449
}
450
}
450
void checkTypeVariableMethods() {
451
void checkTypeVariableMethods(TypeParameter typeParameter) {
451
	char[][] methodSelectors = this.inheritedMethods.keyTable;
452
	char[][] methodSelectors = this.inheritedMethods.keyTable;
452
	nextSelector : for (int s = methodSelectors.length; --s >= 0;) {
453
	nextSelector : for (int s = methodSelectors.length; --s >= 0;) {
453
		if (methodSelectors[s] == null) continue nextSelector;
454
		if (methodSelectors[s] == null) continue nextSelector;
Lines 477-483 Link Here
477
				int count = index + 1;
478
				int count = index + 1;
478
				while (--count > 0 && areReturnTypesEqual(first, matchingInherited[count])){/*empty*/}
479
				while (--count > 0 && areReturnTypesEqual(first, matchingInherited[count])){/*empty*/}
479
				if (count > 0) {  // All inherited methods do NOT have the same vmSignature
480
				if (count > 0) {  // All inherited methods do NOT have the same vmSignature
480
					problemReporter().inheritedMethodsHaveIncompatibleReturnTypes(this.type, matchingInherited, index + 1);
481
					problemReporter().inheritedMethodsHaveIncompatibleReturnTypes(typeParameter, matchingInherited, index + 1);
481
					continue nextSelector;
482
					continue nextSelector;
482
				}
483
				}
483
			}
484
			}
Lines 774-780 Link Here
774
				: itsInterfaces[j];
775
				: itsInterfaces[j];
775
		}
776
		}
776
		computeInheritedMethods(superclass, superInterfaces);
777
		computeInheritedMethods(superclass, superInterfaces);
777
		checkTypeVariableMethods();
778
		checkTypeVariableMethods(someType.scope.referenceContext.typeParameters[i]);
778
	}
779
	}
779
}
780
}
780
}
781
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (-2 / +2 lines)
Lines 2023-2029 Link Here
2023
			"----------\n" + 
2023
			"----------\n" + 
2024
			"1. ERROR in X.java (at line 3)\r\n" + 
2024
			"1. ERROR in X.java (at line 3)\r\n" + 
2025
			"	public class X<T extends I&J> {}\r\n" + 
2025
			"	public class X<T extends I&J> {}\r\n" + 
2026
			"	             ^\n" + 
2026
			"	               ^\n" + 
2027
			"The return type is incompatible with J.foo(), I.foo()\n" + 
2027
			"The return type is incompatible with J.foo(), I.foo()\n" + 
2028
			"----------\n"
2028
			"----------\n"
2029
			// types J and I are incompatible; both define foo(), but with unrelated return types
2029
			// types J and I are incompatible; both define foo(), but with unrelated return types
Lines 2041-2047 Link Here
2041
			"----------\n" + 
2041
			"----------\n" + 
2042
			"1. ERROR in X.java (at line 2)\r\n" + 
2042
			"1. ERROR in X.java (at line 2)\r\n" + 
2043
			"	class A { public Object foo() { return null; } }public class X<T extends A&I> {}\r\n" + 
2043
			"	class A { public Object foo() { return null; } }public class X<T extends A&I> {}\r\n" + 
2044
			"	                                                             ^\n" + 
2044
			"	                                                               ^\n" + 
2045
			"The return type is incompatible with I.foo(), A.foo()\n" + 
2045
			"The return type is incompatible with I.foo(), A.foo()\n" + 
2046
			"----------\n"
2046
			"----------\n"
2047
			// foo() in A cannot implement foo() in I; attempting to use incompatible return type
2047
			// foo() in A cannot implement foo() in I; attempting to use incompatible return type
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java (+108 lines)
Lines 1875-1878 Link Here
1875
		},
1875
		},
1876
		"");
1876
		"");
1877
}
1877
}
1878
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590
1879
// **
1880
public void test047() {
1881
	this.runNegativeTest(
1882
		new String[] {
1883
			"X.java",
1884
			"public class X<T extends I & J> {\n" + 
1885
			"  void foo(T t) {\n" + 
1886
			"  }\n" + 
1887
			"}\n" + 
1888
			"interface I {\n" + 
1889
			"  public int method();\n" + 
1890
			"}\n" + 
1891
			"interface J {\n" + 
1892
			"  public boolean method();\n" + 
1893
			"}\n"
1894
		},
1895
		"----------\n" + 
1896
		"1. ERROR in X.java (at line 1)\n" + 
1897
		"	public class X<T extends I & J> {\n" + 
1898
		"	               ^\n" + 
1899
		"The return type is incompatible with J.method(), I.method()\n" + 
1900
		"----------\n");
1901
}
1902
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590
1903
// Variant: javac complains as well if we attempt to use method, but noone
1904
// complains upon bar or CONSTANT.
1905
public void test048() {
1906
	this.runNegativeTest(
1907
		new String[] {
1908
			"X.java",
1909
			"public class X<T extends I & J> {\n" + 
1910
			"  void foo(T t) {\n" + 
1911
			"    t.method();\n" + 
1912
			"    t.bar();\n" + 
1913
			"    if (t.CONSTANT > 0);\n" + 
1914
			"  }\n" + 
1915
			"}\n" + 
1916
			"interface I {\n" + 
1917
			"  public int method();\n" + 
1918
			"  void bar();\n" + 
1919
			"}\n" + 
1920
			"interface J {\n" + 
1921
			"  public boolean method();\n" + 
1922
			"  static final int CONSTANT = 0;\n" + 
1923
			"}\n"
1924
		},
1925
		"----------\n" + 
1926
		"1. ERROR in X.java (at line 1)\n" + 
1927
		"	public class X<T extends I & J> {\n" + 
1928
		"	               ^\n" + 
1929
		"The return type is incompatible with J.method(), I.method()\n" + 
1930
		"----------\n" + 
1931
		"2. ERROR in X.java (at line 3)\n" + 
1932
		"	t.method();\n" + 
1933
		"	  ^^^^^^\n" + 
1934
		"The method method() is ambiguous for the type T\n" + 
1935
		"----------\n" + 
1936
		"3. WARNING in X.java (at line 5)\n" + 
1937
		"	if (t.CONSTANT > 0);\n" + 
1938
		"	      ^^^^^^^^\n" + 
1939
		"The static field J.CONSTANT should be accessed in a static way\n" + 
1940
		"----------\n");
1941
}
1942
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590
1943
// can't implement both interfaces though
1944
public void test049() {
1945
	this.runNegativeTest(
1946
		new String[] {
1947
			"X.java",
1948
			"interface I {\n" + 
1949
			"  public int method();\n" + 
1950
			"}\n" + 
1951
			"interface J {\n" + 
1952
			"  public boolean method();\n" + 
1953
			"}\n" + 
1954
			"class X implements I, J {\n" + 
1955
			"  public int method() {\n" + 
1956
			"    return 0;\n" + 
1957
			"  }\n" + 
1958
			"}"
1959
		},
1960
		"----------\n" + 
1961
		"1. ERROR in X.java (at line 8)\n" + 
1962
		"	public int method() {\n" + 
1963
		"	       ^^^\n" + 
1964
		"The return type is incompatible with J.method()\n" + 
1965
		"----------\n");
1966
}
1967
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590
1968
// variant: secure the legal case
1969
public void test050() {
1970
	this.runConformTest(
1971
		new String[] {
1972
			"X.java",
1973
			"public class X<T extends I & J> {\n" + 
1974
			"  void foo(T t) {\n" + 
1975
			"  }\n" + 
1976
			"}\n" + 
1977
			"interface I {\n" + 
1978
			"  public int method();\n" + 
1979
			"}\n" + 
1980
			"interface J {\n" + 
1981
			"  public int method();\n" + 
1982
			"}\n"
1983
		},
1984
		"");
1985
}
1878
}
1986
}

Return to bug 163590