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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java (-28 lines)
Lines 91-97 Link Here
91
		// iterate the field declarations to create the bindings, lose all duplicates
91
		// iterate the field declarations to create the bindings, lose all duplicates
92
		FieldBinding[] fieldBindings = new FieldBinding[count];
92
		FieldBinding[] fieldBindings = new FieldBinding[count];
93
		HashtableOfObject knownFieldNames = new HashtableOfObject(count);
93
		HashtableOfObject knownFieldNames = new HashtableOfObject(count);
94
		boolean duplicate = false;
95
		count = 0;
94
		count = 0;
96
		for (int i = 0; i < size; i++) {
95
		for (int i = 0; i < size; i++) {
97
			FieldDeclaration field = fields[i];
96
			FieldDeclaration field = fields[i];
Lines 105-123 Link Here
105
				checkAndSetModifiersForField(fieldBinding, field);
104
				checkAndSetModifiersForField(fieldBinding, field);
106
105
107
				if (knownFieldNames.containsKey(field.name)) {
106
				if (knownFieldNames.containsKey(field.name)) {
108
					duplicate = true;
109
					FieldBinding previousBinding = (FieldBinding) knownFieldNames.get(field.name);
110
					if (previousBinding != null) {
111
						for (int f = 0; f < i; f++) {
112
							FieldDeclaration previousField = fields[f];
113
							if (previousField.binding == previousBinding) {
114
								problemReporter().duplicateFieldInType(sourceType, previousField);
115
								previousField.binding = null;
116
								break;
117
							}
118
						}
119
					}
120
					knownFieldNames.put(field.name, null); // ensure that the duplicate field is found & removed
121
					problemReporter().duplicateFieldInType(sourceType, field);
107
					problemReporter().duplicateFieldInType(sourceType, field);
122
					field.binding = null;
108
					field.binding = null;
123
				} else {
109
				} else {
Lines 128-147 Link Here
128
			}
114
			}
129
		}
115
		}
130
		// remove duplicate fields
116
		// remove duplicate fields
131
		if (duplicate) {
132
			FieldBinding[] newFieldBindings = new FieldBinding[fieldBindings.length];
133
			// we know we'll be removing at least 1 duplicate name
134
			size = count;
135
			count = 0;
136
			for (int i = 0; i < size; i++) {
137
				FieldBinding fieldBinding = fieldBindings[i];
138
				if (knownFieldNames.get(fieldBinding.name) != null) {
139
					fieldBinding.id = count;
140
					newFieldBindings[count++] = fieldBinding;
141
				}
142
			}
143
			fieldBindings = newFieldBindings;
144
		}
145
		if (count != fieldBindings.length)
117
		if (count != fieldBindings.length)
146
			System.arraycopy(fieldBindings, 0, fieldBindings = new FieldBinding[count], 0, count);
118
			System.arraycopy(fieldBindings, 0, fieldBindings = new FieldBinding[count], 0, count);
147
		sourceType.tagBits &= ~(TagBits.AreFieldsSorted|TagBits.AreFieldsComplete); // in case some static imports reached already into this type
119
		sourceType.tagBits &= ~(TagBits.AreFieldsSorted|TagBits.AreFieldsComplete); // in case some static imports reached already into this type
(-)src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java (-6 / +1 lines)
Lines 176-187 Link Here
176
			"}"
176
			"}"
177
		},
177
		},
178
		"----------\n" +
178
		"----------\n" +
179
		"1. ERROR in X.java (at line 3)\n" +
179
		"1. ERROR in X.java (at line 6)\n" +
180
		"	BLEU, \n" +
181
		"	^^^^\n" +
182
		"Duplicate field X.BLEU\n" +
183
		"----------\n" +
184
		"2. ERROR in X.java (at line 6)\n" +
185
		"	BLEU;\n" +
180
		"	BLEU;\n" +
186
		"	^^^^\n" +
181
		"	^^^^\n" +
187
		"Duplicate field X.BLEU\n" +
182
		"Duplicate field X.BLEU\n" +

Return to bug 146768