View | Details | Raw Unified | Return to bug 168331 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java (-2 / +2 lines)
Lines 5347-5353 Link Here
5347
		"----------\n");
5347
		"----------\n");
5348
}
5348
}
5349
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=168331
5349
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=168331
5350
public void _test133() {
5350
public void test133() {
5351
	if (this.complianceLevel.compareTo(COMPLIANCE_1_5) >= 0) {
5351
	if (this.complianceLevel.compareTo(COMPLIANCE_1_5) >= 0) {
5352
		this.runConformTest(
5352
		this.runConformTest(
5353
			new String[] {
5353
			new String[] {
Lines 5382-5388 Link Here
5382
	}
5382
	}
5383
}
5383
}
5384
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=168331
5384
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=168331
5385
public void _test134() {
5385
public void test134() {
5386
	if (this.complianceLevel.compareTo(COMPLIANCE_1_5) >= 0) {
5386
	if (this.complianceLevel.compareTo(COMPLIANCE_1_5) >= 0) {
5387
		this.runConformTest(
5387
		this.runConformTest(
5388
			new String[] {
5388
			new String[] {
(-)src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (-4 / +9 lines)
Lines 708-721 Link Here
708
				"abstract class X2 extends A implements J {}\n"
708
				"abstract class X2 extends A implements J {}\n"
709
			},
709
			},
710
			"----------\n" + 
710
			"----------\n" + 
711
			"1. ERROR in A.java (at line 2)\r\n" + 
711
			"1. ERROR in A.java (at line 1)\n" + 
712
			"	interface I extends J { Object foo(); }\r\n" + 
712
			"	abstract class A implements I {}\n" + 
713
			"	               ^\n" + 
714
			"The return type is incompatible with J.foo(), I.foo()\n" + 
715
			"----------\n" + 
716
			"2. ERROR in A.java (at line 2)\n" + 
717
			"	interface I extends J { Object foo(); }\n" + 
713
			"	                        ^^^^^^\n" + 
718
			"	                        ^^^^^^\n" + 
714
			"The return type is incompatible with J.foo()\n" + 
719
			"The return type is incompatible with J.foo()\n" + 
715
			"----------\n" + 
720
			"----------\n" + 
716
			"----------\n" + 
721
			"----------\n" + 
717
			"1. ERROR in X.java (at line 1)\r\n" + 
722
			"1. ERROR in X.java (at line 1)\n" + 
718
			"	abstract class X2 extends A implements J {}\r\n" + 
723
			"	abstract class X2 extends A implements J {}\n" + 
719
			"	               ^^\n" + 
724
			"	               ^^\n" + 
720
			"The return type is incompatible with I.foo(), J.foo()\n" + 
725
			"The return type is incompatible with I.foo(), J.foo()\n" + 
721
			"----------\n"
726
			"----------\n"
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (-6 / +16 lines)
Lines 31465-31486 Link Here
31465
			},
31465
			},
31466
			"S100MyClass = [Terry]MyClass = [Corbet]SUCCESS");
31466
			"S100MyClass = [Terry]MyClass = [Corbet]SUCCESS");
31467
}
31467
}
31468
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643
31468
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643
31469
public void test0987() {
31469
public void test0987() {
31470
	String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6
31470
	String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6
31471
	?	"----------\n" + 
31471
	?	"----------\n" + 
31472
		"1. ERROR in X.java (at line 11)\n" + 
31472
		"1. ERROR in X.java (at line 7)\n" + 
31473
		"	abstract class GLinkElementView<M,CM> extends AbstractLinkView<M> {}\n" + 
31474
		"	               ^^^^^^^^^^^^^^^^\n" + 
31475
		"The return type is incompatible with EditPart.getViewer(), AbstractLinkView<M>.getViewer()\n" + 
31476
		"----------\n" + 
31477
		"2. ERROR in X.java (at line 11)\n" + 
31473
		"	public ISheetViewer getViewer() { return null; }	\n" + 
31478
		"	public ISheetViewer getViewer() { return null; }	\n" + 
31474
		"	       ^^^^^^^^^^^^\n" + 
31479
		"	       ^^^^^^^^^^^^\n" + 
31475
		"The return type is incompatible with EditPart.getViewer()\n" + 
31480
		"The return type is incompatible with EditPart.getViewer()\n" + 
31476
		"----------\n" + 
31481
		"----------\n" + 
31477
		"2. ERROR in X.java (at line 11)\n" + 
31482
		"3. ERROR in X.java (at line 11)\n" + 
31478
		"	public ISheetViewer getViewer() { return null; }	\n" + 
31483
		"	public ISheetViewer getViewer() { return null; }	\n" + 
31479
		"	                    ^^^^^^^^^^^\n" + 
31484
		"	                    ^^^^^^^^^^^\n" + 
31480
		"The method getViewer() of type AbstractLinkView<M> must override a superclass method\n" + 
31485
		"The method getViewer() of type AbstractLinkView<M> must override a superclass method\n" + 
31481
		"----------\n"
31486
		"----------\n"
31482
	:	"----------\n" + 
31487
	:	"----------\n" + 
31483
		"1. ERROR in X.java (at line 11)\n" + 
31488
		"1. ERROR in X.java (at line 7)\n" + 
31489
		"	abstract class GLinkElementView<M,CM> extends AbstractLinkView<M> {}\n" + 
31490
		"	               ^^^^^^^^^^^^^^^^\n" + 
31491
		"The return type is incompatible with EditPart.getViewer(), AbstractLinkView<M>.getViewer()\n" + 
31492
		"----------\n" + 
31493
		"2. ERROR in X.java (at line 11)\n" + 
31484
		"	public ISheetViewer getViewer() { return null; }	\n" + 
31494
		"	public ISheetViewer getViewer() { return null; }	\n" + 
31485
		"	       ^^^^^^^^^^^^\n" + 
31495
		"	       ^^^^^^^^^^^^\n" + 
31486
		"The return type is incompatible with EditPart.getViewer()\n" + 
31496
		"The return type is incompatible with EditPart.getViewer()\n" + 
Lines 31521-31527 Link Here
31521
			},
31531
			},
31522
			expectedOutput);
31532
			expectedOutput);
31523
}
31533
}
31524
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643 - variation
31534
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643 - variation
31525
public void test0988() {
31535
public void test0988() {
31526
	this.runNegativeTest(
31536
	this.runNegativeTest(
31527
			new String[] {
31537
			new String[] {
Lines 31572-31578 Link Here
31572
			"1. ERROR in X.java (at line 7)\n" + 
31582
			"1. ERROR in X.java (at line 7)\n" + 
31573
			"	abstract class GLinkElementView<M,CM> extends AbstractLinkView<M> {}\n" + 
31583
			"	abstract class GLinkElementView<M,CM> extends AbstractLinkView<M> {}\n" + 
31574
			"	               ^^^^^^^^^^^^^^^^\n" + 
31584
			"	               ^^^^^^^^^^^^^^^^\n" + 
31575
			"The return type is incompatible with AbstractEditPart.getViewer(), AbstractLinkView<M>.getViewer()\n" + 
31585
			"The return type is incompatible with ILinkViewElement.getViewer(), AbstractEditPart.getViewer(), AbstractLinkView<M>.getViewer()\n" + 
31576
			"----------\n" + 
31586
			"----------\n" + 
31577
			"2. ERROR in X.java (at line 11)\n" + 
31587
			"2. ERROR in X.java (at line 11)\n" + 
31578
			"	public SheetViewer getViewer() { return null; }	\n" + 
31588
			"	public SheetViewer getViewer() { return null; }	\n" + 
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java (-2 / +23 lines)
Lines 1457-1463 Link Here
1457
		"");
1457
		"");
1458
}
1458
}
1459
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162073
1459
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162073
1460
public void _test032() {
1460
public void test032() {
1461
	this.runConformTest(
1461
	this.runConformTest(
1462
		new String[] {
1462
		new String[] {
1463
			"X.java",
1463
			"X.java",
Lines 1474-1480 Link Here
1474
		"");
1474
		"");
1475
}
1475
}
1476
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162073
1476
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162073
1477
// variant that passes
1477
// variant that shows that the use of a substitution is needed during the bounds
1478
// check
1479
public void test032a() {
1480
	this.runConformTest(
1481
		new String[] {
1482
			"X.java",
1483
			"class Z { }\n" +
1484
			"class Y <U> extends Z { }" +
1485
			"interface I {\n" + 
1486
			"  <T extends Y<T> & Cloneable> T foo(Number n);\n" + 
1487
			"}\n" + 
1488
			"interface J extends I {\n" + 
1489
			"  XX foo(Number n);\n" + 
1490
			"}\n" + 
1491
			"public abstract class X implements J {\n" + 
1492
			"}\n" + 
1493
			"abstract class XX extends Y<XX> implements Cloneable {}"
1494
		},
1495
		"");
1496
}
1497
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162073
1498
// variant
1478
public void test033() {
1499
public void test033() {
1479
	this.runConformTest(
1500
	this.runConformTest(
1480
		new String[] {
1501
		new String[] {
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java (-2 / +61 lines)
Lines 313-321 Link Here
313
313
314
	super.checkInheritedMethods(methods, length);
314
	super.checkInheritedMethods(methods, length);
315
}
315
}
316
class OneOneSubstitution implements Substitution {
317
	TypeBinding replaced, replacer;
318
	OneOneSubstitution(TypeBinding replaced, TypeBinding replacer) {
319
		this.replaced = replaced;
320
		this.replacer = replacer;
321
	}
322
	public LookupEnvironment environment() { 
323
		return environment; 
324
	}
325
	public boolean isRawSubstitution() { 
326
		return false; 
327
	}
328
	public TypeBinding substitute(TypeVariableBinding typeVariable) {
329
		return typeVariable == replaced ? replacer : typeVariable;
330
	}
331
}
316
boolean checkInheritedReturnTypes(MethodBinding[] methods, int length) {
332
boolean checkInheritedReturnTypes(MethodBinding[] methods, int length) {
317
	if (methods[0].declaringClass.isClass())
333
	if (methods[0].declaringClass.isClass())
318
		return super.checkInheritedReturnTypes(methods, length);
334
		return super.checkInheritedReturnTypes(methods, length);
335
	if (length <= 1) {
336
		return true; // no need to continue since only 1 inherited method is left
337
	}
338
	// get rid of overriden methods coming from interfaces - if any
339
	MethodBinding methodsToCheck[] = new MethodBinding[length];	// must not nullify methods slots in place
340
	int count = length;
341
	for (int i = 0; i < length; i++) {
342
		methodsToCheck[i] = methods[i];
343
	}
344
	MethodBinding existingMethod, inheritedMethod, substitute;
345
	for (int i = 0; i < length; i++) {
346
		if ((existingMethod = methodsToCheck[i]) != null) {
347
			for (int j = 0; j < length; j++) {
348
				if (i != j && (inheritedMethod = methodsToCheck[j]) != null &&
349
						existingMethod.declaringClass.implementsInterface(inheritedMethod.declaringClass, true)) {
350
					substitute = computeSubstituteMethod(inheritedMethod, existingMethod);
351
					if (substitute != null && doesSubstituteMethodOverride(existingMethod, substitute) &&
352
							(existingMethod.returnType.isCompatibleWith(substitute.returnType) ||
353
									substitute.returnType instanceof TypeVariableBinding &&
354
									((TypeVariableBinding) substitute.returnType).
355
										boundCheck(
356
											new OneOneSubstitution(substitute.returnType, existingMethod.returnType),
357
											existingMethod.returnType)  == TypeConstants.OK)) {
358
						count--;
359
						methodsToCheck[j] = null;
360
					}
361
				}
362
			}
363
		}
364
	}
365
	if (count < length) {
366
		if (count == 1) { 
367
			return true; // no need to continue since only 1 inherited method is left
368
		}
369
		for (int i = 0, j = 0; j < count; i++) {
370
			if (methodsToCheck[i] != null) {
371
				methodsToCheck[j++] = methodsToCheck[i];
372
			}
373
		}
374
		methods = methodsToCheck;
375
		length = count;
376
	} // else keep methods unchanged for further checks
319
377
320
	// its possible in 1.5 that A is compatible with B & C, but B is not compatible with C
378
	// its possible in 1.5 that A is compatible with B & C, but B is not compatible with C
321
	for (int i = 0, l = length - 1; i < l;) {
379
	for (int i = 0, l = length - 1; i < l;) {
Lines 552-565 Link Here
552
	// one has type variables and substituteTwo did not pass bounds check in computeSubstituteMethod()
610
	// one has type variables and substituteTwo did not pass bounds check in computeSubstituteMethod()
553
	return one.typeVariables != Binding.NO_TYPE_VARIABLES && !(substituteTwo instanceof ParameterizedGenericMethodBinding);
611
	return one.typeVariables != Binding.NO_TYPE_VARIABLES && !(substituteTwo instanceof ParameterizedGenericMethodBinding);
554
}
612
}
613
// caveat: returns false if a method is implemented but needs that a bridge 
614
//         method be generated
555
boolean isInterfaceMethodImplemented(MethodBinding inheritedMethod, MethodBinding existingMethod, ReferenceBinding superType) {
615
boolean isInterfaceMethodImplemented(MethodBinding inheritedMethod, MethodBinding existingMethod, ReferenceBinding superType) {
556
	if (inheritedMethod.original() != inheritedMethod && existingMethod.declaringClass.isInterface())
616
	if (inheritedMethod.original() != inheritedMethod && existingMethod.declaringClass.isInterface())
557
		return false; // must hold onto ParameterizedMethod to see if a bridge method is necessary
617
		return false; // must hold onto ParameterizedMethod to see if a bridge method is necessary
558
618
559
	inheritedMethod = computeSubstituteMethod(inheritedMethod, existingMethod);
619
	inheritedMethod = computeSubstituteMethod(inheritedMethod, existingMethod);
560
	return inheritedMethod != null
620
	return inheritedMethod != null
561
		&& (inheritedMethod.returnType == existingMethod.returnType ||
621
		&& inheritedMethod.returnType == existingMethod.returnType
562
				inheritedMethod.returnType.isCompatibleWith(inheritedMethod.returnType))
563
		&& super.isInterfaceMethodImplemented(inheritedMethod, existingMethod, superType);
622
		&& super.isInterfaceMethodImplemented(inheritedMethod, existingMethod, superType);
564
}
623
}
565
SimpleSet findSuperinterfaceCollisions(ReferenceBinding superclass, ReferenceBinding[] superInterfaces) {
624
SimpleSet findSuperinterfaceCollisions(ReferenceBinding superclass, ReferenceBinding[] superInterfaces) {

Return to bug 168331