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

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java (-4 lines)
Lines 500-512 Link Here
500
	int[] toSkip = null;
500
	int[] toSkip = null;
501
	if (iMethods != null) {
501
	if (iMethods != null) {
502
		total = initialTotal = iMethods.length;
502
		total = initialTotal = iMethods.length;
503
		boolean keepBridgeMethods = sourceLevel < ClassFileConstants.JDK1_5
504
			&& this.environment.globalOptions.complianceLevel >= ClassFileConstants.JDK1_5;
505
		for (int i = total; --i >= 0;) {
503
		for (int i = total; --i >= 0;) {
506
			IBinaryMethod method = iMethods[i];
504
			IBinaryMethod method = iMethods[i];
507
			if ((method.getModifiers() & ClassFileConstants.AccSynthetic) != 0) {
505
			if ((method.getModifiers() & ClassFileConstants.AccSynthetic) != 0) {
508
				if (keepBridgeMethods && (method.getModifiers() & ClassFileConstants.AccBridge) != 0)
509
					continue; // want to see bridge methods as real methods
510
				// discard synthetics methods
506
				// discard synthetics methods
511
				if (toSkip == null) toSkip = new int[iMethods.length];
507
				if (toSkip == null) toSkip = new int[iMethods.length];
512
				toSkip[i] = -1;
508
				toSkip[i] = -1;
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java (-24 / +1 lines)
Lines 41-70 Link Here
41
	return true;
41
	return true;
42
}
42
}
43
boolean areReturnTypesEqual(MethodBinding one, MethodBinding substituteTwo) {
43
boolean areReturnTypesEqual(MethodBinding one, MethodBinding substituteTwo) {
44
	if (one.returnType == substituteTwo.returnType) return true;
44
	return areReturnTypesCompatible(one, substituteTwo);
45
46
	// short is compatible with int, but as far as covariance is concerned, its not
47
	if (one.returnType.isBaseType()) return false;
48
49
	if (!one.declaringClass.isInterface()) {
50
		if (one.declaringClass.id == TypeIds.T_JavaLangObject)
51
			return substituteTwo.returnType.isCompatibleWith(one.returnType); // interface methods inherit from Object
52
		return one.returnType.isCompatibleWith(substituteTwo.returnType);
53
	}
54
55
	// check for methods from Object, every interface inherits from Object
56
	if (substituteTwo.declaringClass.id == TypeIds.T_JavaLangObject)
57
		return one.returnType.isCompatibleWith(substituteTwo.returnType);
58
59
	// both are interfaces, see if they're related
60
	if (one.declaringClass.implementsInterface(substituteTwo.declaringClass, true))
61
		return one.returnType.isCompatibleWith(substituteTwo.returnType);
62
	if (substituteTwo.declaringClass.implementsInterface(one.declaringClass, true))
63
		return substituteTwo.returnType.isCompatibleWith(one.returnType);
64
65
	// unrelated interfaces... one must be a subtype of the other
66
	return one.returnType.isCompatibleWith(substituteTwo.returnType)
67
		|| substituteTwo.returnType.isCompatibleWith(one.returnType);
68
}
45
}
69
boolean areTypesEqual(TypeBinding one, TypeBinding two) {
46
boolean areTypesEqual(TypeBinding one, TypeBinding two) {
70
	if (one == two) return true;
47
	if (one == two) return true;
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java (-1 / +38 lines)
Lines 23-28 Link Here
23
	ReferenceBinding runtimeException;
23
	ReferenceBinding runtimeException;
24
	ReferenceBinding errorException;
24
	ReferenceBinding errorException;
25
	LookupEnvironment environment;
25
	LookupEnvironment environment;
26
	boolean allowCompatibleReturnTypes;
26
/*
27
/*
27
Binding creation is responsible for reporting all problems with types:
28
Binding creation is responsible for reporting all problems with types:
28
	- all modifier problems (duplicates & multiple visibility modifiers + incompatible combinations - abstract/final)
29
	- all modifier problems (duplicates & multiple visibility modifiers + incompatible combinations - abstract/final)
Lines 47-52 Link Here
47
	this.runtimeException = null;
48
	this.runtimeException = null;
48
	this.errorException = null;
49
	this.errorException = null;
49
	this.environment = environment;
50
	this.environment = environment;
51
	this.allowCompatibleReturnTypes =
52
		environment.globalOptions.complianceLevel >= org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_5
53
			&& environment.globalOptions.sourceLevel < org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_5;
50
}
54
}
51
boolean areMethodsEqual(MethodBinding one, MethodBinding two) {
55
boolean areMethodsEqual(MethodBinding one, MethodBinding two) {
52
	return doesMethodOverride(one, two) && areReturnTypesEqual(one, two);
56
	return doesMethodOverride(one, two) && areReturnTypesEqual(one, two);
Lines 63-70 Link Here
63
		if (!areTypesEqual(oneArgs[i], twoArgs[i])) return false;
67
		if (!areTypesEqual(oneArgs[i], twoArgs[i])) return false;
64
	return true;
68
	return true;
65
}
69
}
70
boolean areReturnTypesCompatible(MethodBinding one, MethodBinding substituteTwo) {
71
	if (one.returnType == substituteTwo.returnType) return true;
72
73
	// short is compatible with int, but as far as covariance is concerned, its not
74
	if (one.returnType.isBaseType()) return false;
75
76
	if (!one.declaringClass.isInterface()) {
77
		if (one.declaringClass.id == TypeIds.T_JavaLangObject)
78
			return substituteTwo.returnType.isCompatibleWith(one.returnType); // interface methods inherit from Object
79
		return one.returnType.isCompatibleWith(substituteTwo.returnType);
80
	}
81
82
	// check for methods from Object, every interface inherits from Object
83
	if (substituteTwo.declaringClass.id == TypeIds.T_JavaLangObject)
84
		return one.returnType.isCompatibleWith(substituteTwo.returnType);
85
86
	// both are interfaces, see if they're related
87
	if (one.declaringClass.implementsInterface(substituteTwo.declaringClass, true))
88
		return one.returnType.isCompatibleWith(substituteTwo.returnType);
89
	if (substituteTwo.declaringClass.implementsInterface(one.declaringClass, true))
90
		return substituteTwo.returnType.isCompatibleWith(one.returnType);
91
92
	// unrelated interfaces... one must be a subtype of the other
93
	return one.returnType.isCompatibleWith(substituteTwo.returnType)
94
		|| substituteTwo.returnType.isCompatibleWith(one.returnType);
95
}
66
boolean areReturnTypesEqual(MethodBinding one, MethodBinding two) {
96
boolean areReturnTypesEqual(MethodBinding one, MethodBinding two) {
67
	return areTypesEqual(one.returnType, two.returnType);
97
	if (areTypesEqual(one.returnType, two.returnType)) return true;
98
99
	// when sourceLevel < 1.5 but compliance >= 1.5, allow return types in binaries to be compatible instead of just equal
100
	if (this.allowCompatibleReturnTypes)
101
		if (one.declaringClass instanceof BinaryTypeBinding && two.declaringClass instanceof BinaryTypeBinding)
102
			if (areReturnTypesCompatible(one, two))
103
				return true;
104
	return false;
68
}
105
}
69
boolean areTypesEqual(TypeBinding one, TypeBinding two) {
106
boolean areTypesEqual(TypeBinding one, TypeBinding two) {
70
	if (one == two) return true;
107
	if (one == two) return true;

Return to bug 139099