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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java (-59 / +2 lines)
Lines 1099-1105 Link Here
1099
1099
1100
		// find & report collision cases
1100
		// find & report collision cases
1101
		boolean complyTo15 = this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5;
1101
		boolean complyTo15 = this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5;
1102
		boolean complyTo17 = this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_7;
1103
		for (int i = 0, length = this.methods.length; i < length; i++) {
1102
		for (int i = 0, length = this.methods.length; i < length; i++) {
1104
			MethodBinding method = resolvedMethods[i];
1103
			MethodBinding method = resolvedMethods[i];
1105
			if (method == null)
1104
			if (method == null)
Lines 1113-1176 Link Here
1113
				if (!CharOperation.equals(selector, method2.selector))
1112
				if (!CharOperation.equals(selector, method2.selector))
1114
					break nextSibling; // methods with same selector are contiguous
1113
					break nextSibling; // methods with same selector are contiguous
1115
1114
1116
				if (complyTo15 && method.returnType != null && method2.returnType != null) {
1115
				if (complyTo15 ? !method.areParameterErasuresEqual(method2) : !method.areParametersEqual(method2))
1117
					// 8.4.2, for collision to be detected between m1 and m2:
1116
					continue nextSibling; // otherwise duplicates / name clash
1118
					// signature(m1) == signature(m2) i.e. same arity, same type parameter count, can be substituted
1119
					// signature(m1) == erasure(signature(m2)) or erasure(signature(m1)) == signature(m2)
1120
					TypeBinding[] params1 = method.parameters;
1121
					TypeBinding[] params2 = method2.parameters;
1122
					int pLength = params1.length;
1123
					if (pLength != params2.length)
1124
						continue nextSibling;
1125
1126
					TypeVariableBinding[] vars = method.typeVariables;
1127
					TypeVariableBinding[] vars2 = method2.typeVariables;
1128
					boolean equalTypeVars = vars == vars2;
1129
					MethodBinding subMethod = method2;
1130
					if (!equalTypeVars) {
1131
						MethodBinding temp = method.computeSubstitutedMethod(method2, this.scope.environment());
1132
						if (temp != null) {
1133
							equalTypeVars = true;
1134
							subMethod = temp;
1135
						}
1136
					}
1137
					boolean equalParams = method.areParametersEqual(subMethod);
1138
					if (equalParams && equalTypeVars) {
1139
						// duplicates regardless of return types
1140
					} else if ((complyTo17 || method.returnType.erasure() == subMethod.returnType.erasure())
1141
						&& (equalParams || method.areParameterErasuresEqual(method2))) {
1142
						// with fix for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950
1143
						// we now ignore return types when detecting duplicates, just as we did before 1.5 
1144
						// name clash for sure if not duplicates, report as duplicates
1145
						// FYI for now we will only make this change when compliance is set to 1.7 or higher
1146
					} else if (!equalTypeVars && vars != Binding.NO_TYPE_VARIABLES && vars2 != Binding.NO_TYPE_VARIABLES) {
1147
						// type variables are different so we can distinguish between methods
1148
						continue nextSibling;
1149
					} else if (pLength > 0) {
1150
						// check to see if the erasure of either method is equal to the other
1151
						int index = pLength;
1152
						for (; --index >= 0;) {
1153
							if (params1[index] != params2[index].erasure())
1154
								break;
1155
							if (params1[index] == params2[index]) {
1156
								TypeBinding type = params1[index].leafComponentType();
1157
								if (type instanceof SourceTypeBinding && type.typeVariables() != Binding.NO_TYPE_VARIABLES) {
1158
									index = pLength; // handle comparing identical source types like X<T>... its erasure is itself BUT we need to answer false
1159
									break;
1160
								}
1161
							}
1162
						}
1163
						if (index >= 0 && index < pLength) {
1164
							for (index = pLength; --index >= 0;)
1165
								if (params1[index].erasure() != params2[index])
1166
									break;
1167
						}
1168
						if (index >= 0)
1169
							continue nextSibling;
1170
					}
1171
				} else if (!method.areParametersEqual(method2)) { // prior to 1.5, parameter identity meant a collision case
1172
					continue nextSibling;
1173
				}
1174
				boolean isEnumSpecialMethod = isEnum() && (CharOperation.equals(selector,TypeConstants.VALUEOF) || CharOperation.equals(selector,TypeConstants.VALUES));
1117
				boolean isEnumSpecialMethod = isEnum() && (CharOperation.equals(selector,TypeConstants.VALUEOF) || CharOperation.equals(selector,TypeConstants.VALUES));
1175
				// report duplicate
1118
				// report duplicate
1176
				boolean removeMethod2 = true;
1119
				boolean removeMethod2 = true;
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java (-15 lines)
Lines 11-17 Link Here
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.ast.TypeParameter;
14
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
15
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
14
import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;
16
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
15
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
17
16
Lines 549-561 Link Here
549
boolean detectInheritedNameClash(MethodBinding inherited, MethodBinding otherInherited) {
548
boolean detectInheritedNameClash(MethodBinding inherited, MethodBinding otherInherited) {
550
	if (!inherited.areParameterErasuresEqual(otherInherited))
549
	if (!inherited.areParameterErasuresEqual(otherInherited))
551
		return false;
550
		return false;
552
	if (this.environment.globalOptions.sourceLevel < ClassFileConstants.JDK1_7) {
553
		// with fix for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950
554
		// we now ignore return types when detecting name clashes
555
		// FYI for now we will only make this change when compliance is set to 1.7 or higher
556
		if (inherited.returnType.erasure() != otherInherited.returnType.erasure())
557
			return false;
558
	}
559
	// skip it if otherInherited is defined by a subtype of inherited's declaringClass
551
	// skip it if otherInherited is defined by a subtype of inherited's declaringClass
560
	if (inherited.declaringClass.erasure() != otherInherited.declaringClass.erasure())
552
	if (inherited.declaringClass.erasure() != otherInherited.declaringClass.erasure())
561
		if (inherited.declaringClass.findSuperTypeOriginatingFrom(otherInherited.declaringClass) != null)
553
		if (inherited.declaringClass.findSuperTypeOriginatingFrom(otherInherited.declaringClass) != null)
Lines 568-580 Link Here
568
	MethodBinding original = inherited.original(); // can be the same as inherited
560
	MethodBinding original = inherited.original(); // can be the same as inherited
569
	if (!current.areParameterErasuresEqual(original))
561
	if (!current.areParameterErasuresEqual(original))
570
		return false;
562
		return false;
571
	if (this.environment.globalOptions.sourceLevel < ClassFileConstants.JDK1_7) {
572
		// with fix for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950
573
		// we now ignore return types when detecting name clashes
574
		// FYI for now we will only make this change when compliance is set to 1.7 or higher
575
		if (current.returnType.erasure() != original.returnType.erasure())
576
			return false;
577
	}
578
563
579
	problemReporter(current).methodNameClash(current, inherited.declaringClass.isRawType() ? inherited : original);
564
	problemReporter(current).methodNameClash(current, inherited.declaringClass.isRawType() ? inherited : original);
580
	return true;
565
	return true;
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java (-5 / +14 lines)
Lines 161-173 Link Here
161
			arguments[i] = env.convertToRawType(var.upperBound(), false /*do not force conversion of enclosing types*/);
161
			arguments[i] = env.convertToRawType(var.upperBound(), false /*do not force conversion of enclosing types*/);
162
		} else {
162
		} else {
163
			// use an intersection type to retain full bound information if more than 1 bound
163
			// use an intersection type to retain full bound information if more than 1 bound
164
			TypeBinding rawSuperclass = env.convertToRawType(var.superclass(), false);
165
			TypeBinding[] itsSuperinterfaces = var.superInterfaces();
164
			TypeBinding[] itsSuperinterfaces = var.superInterfaces();
166
			int superLength = itsSuperinterfaces.length;
165
			int superLength = itsSuperinterfaces.length;
167
			TypeBinding[] rawSuperinterfaces = new TypeBinding[superLength];
166
			TypeBinding rawFirstBound = null;
168
			for (int s = 0; s < superLength; s++)
167
			TypeBinding[] rawOtherBounds = null;
169
				rawSuperinterfaces[s] = env.convertToRawType(itsSuperinterfaces[s], false);
168
			if (var.boundsCount() == superLength) {
170
			arguments[i] = env.createWildcard(null, 0, rawSuperclass, rawSuperinterfaces, org.eclipse.jdt.internal.compiler.ast.Wildcard.EXTENDS);
169
				rawFirstBound = env.convertToRawType(itsSuperinterfaces[0], false);
170
				rawOtherBounds = new TypeBinding[superLength - 1];
171
				for (int s = 1; s < superLength; s++)
172
					rawOtherBounds[s - 1] = env.convertToRawType(itsSuperinterfaces[s], false);
173
			} else {
174
				rawFirstBound = env.convertToRawType(var.superclass(), false);
175
				rawOtherBounds = new TypeBinding[superLength];
176
				for (int s = 0; s < superLength; s++)
177
					rawOtherBounds[s] = env.convertToRawType(itsSuperinterfaces[s], false);
178
			}
179
			arguments[i] = env.createWildcard(null, 0, rawFirstBound, rawOtherBounds, org.eclipse.jdt.internal.compiler.ast.Wildcard.EXTENDS);
171
		}
180
		}
172
	}
181
	}
173
	return env.createParameterizedGenericMethod(this, arguments);
182
	return env.createParameterizedGenericMethod(this, arguments);

Return to bug 289247