Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: lib/compiler/implementation/resolver.dart

Issue 10837140: Make addGetterOrSetter (now: defineAccessor) not add the abstract field as a member. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cleaner validation of member accessors. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/compiler/implementation/elements/elements.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 interface TreeElements { 5 interface TreeElements {
6 Element operator[](Node node); 6 Element operator[](Node node);
7 Selector getSelector(Send send); 7 Selector getSelector(Send send);
8 Type getType(TypeAnnotation annotation); 8 Type getType(TypeAnnotation annotation);
9 } 9 }
10 10
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 272
273 void checkMembers(ClassElement cls) { 273 void checkMembers(ClassElement cls) {
274 if (cls === compiler.objectClass) return; 274 if (cls === compiler.objectClass) return;
275 cls.forEachMember((holder, member) { 275 cls.forEachMember((holder, member) {
276 checkAbstractField(member); 276 checkAbstractField(member);
277 checkValidOverride(member, cls.lookupSuperMember(member.name)); 277 checkValidOverride(member, cls.lookupSuperMember(member.name));
278 }); 278 });
279 } 279 }
280 280
281 void checkAbstractField(Element member) { 281 void checkAbstractField(Element member) {
282 if (member is !AbstractFieldElement) return; 282 // Only check for getters. The test can only fail if there is both a setter
283 if (member.getter === null) return; 283 // and a getter with the same name, and we only need to check each abstract
284 if (member.setter === null) return; 284 // field once, so we just ignore setters.
285 int getterFlags = member.getter.modifiers.flags | Modifiers.FLAG_ABSTRACT; 285 if (!member.isGetter()) return;
286 int setterFlags = member.setter.modifiers.flags | Modifiers.FLAG_ABSTRACT; 286
287 // Find the associated abstract field.
288 ClassElement classElement = member.getEnclosingClass();
289 Element lookupElement = classElement.lookupLocalMember(member.name);
290 if (lookupElement === null) {
291 compiler.internalErrorOnElement(member,
292 "No abstract field for accessor");
293 } else if (lookupElement.kind !== ElementKind.ABSTRACT_FIELD) {
294 compiler.internalErrorOnElement(
295 member, "Inaccessible abstract field for accessor");
296 }
297 AbstractFieldElement field = lookupElement;
298
299 if (field.getter === null) return;
300 if (field.setter === null) return;
301 int getterFlags = field.getter.modifiers.flags | Modifiers.FLAG_ABSTRACT;
302 int setterFlags = field.setter.modifiers.flags | Modifiers.FLAG_ABSTRACT;
287 if (getterFlags !== setterFlags) { 303 if (getterFlags !== setterFlags) {
288 final mismatchedFlags = 304 final mismatchedFlags =
289 new Modifiers.withFlags(null, getterFlags ^ setterFlags); 305 new Modifiers.withFlags(null, getterFlags ^ setterFlags);
290 compiler.reportMessage( 306 compiler.reportMessage(
291 compiler.spanFromElement(member.getter), 307 compiler.spanFromElement(field.getter),
292 MessageKind.GETTER_MISMATCH.error([mismatchedFlags]), 308 MessageKind.GETTER_MISMATCH.error([mismatchedFlags]),
293 api.Diagnostic.ERROR); 309 api.Diagnostic.ERROR);
294 compiler.reportMessage( 310 compiler.reportMessage(
295 compiler.spanFromElement(member.setter), 311 compiler.spanFromElement(field.setter),
296 MessageKind.SETTER_MISMATCH.error([mismatchedFlags]), 312 MessageKind.SETTER_MISMATCH.error([mismatchedFlags]),
297 api.Diagnostic.ERROR); 313 api.Diagnostic.ERROR);
298 } 314 }
299 } 315 }
300 316
301 reportErrorWithContext(Element errorneousElement, 317 reportErrorWithContext(Element errorneousElement,
302 MessageKind errorMessage, 318 MessageKind errorMessage,
303 Element contextElement, 319 Element contextElement,
304 MessageKind contextMessage) { 320 MessageKind contextMessage) {
305 compiler.reportMessage( 321 compiler.reportMessage(
(...skipping 2220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2526 TopScope(LibraryElement library) : super(null, library); 2542 TopScope(LibraryElement library) : super(null, library);
2527 Element lookup(SourceString name) { 2543 Element lookup(SourceString name) {
2528 return library.find(name); 2544 return library.find(name);
2529 } 2545 }
2530 2546
2531 Element add(Element newElement) { 2547 Element add(Element newElement) {
2532 throw "Cannot add an element in the top scope"; 2548 throw "Cannot add an element in the top scope";
2533 } 2549 }
2534 String toString() => '$element'; 2550 String toString() => '$element';
2535 } 2551 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/elements/elements.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698