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

Unified Diff: lib/compiler/implementation/world.dart

Issue 10834343: Fix access to fields that didn't exist in the class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/cast2_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/world.dart
diff --git a/lib/compiler/implementation/world.dart b/lib/compiler/implementation/world.dart
index 38615cca942e177f64673b850199e8a4c06ed74f..9e8dfe3f1288aa224201d615da8f0b3c95fbe728 100644
--- a/lib/compiler/implementation/world.dart
+++ b/lib/compiler/implementation/world.dart
@@ -30,7 +30,8 @@ class World {
/**
* Returns a [MemberSet] that contains the possible targets of the given
- * [selector] on a receiver with the given [type].
+ * [selector] on a receiver with the given [type]. This includes all sub
+ * types.
*/
MemberSet _memberSetFor(Type type, Selector selector) {
assert(compiler !== null);
@@ -55,23 +56,21 @@ class World {
}
/**
- * Returns the single field with the given [selector]. If there is no such
- * field, or there are multiple possible fields returns [:null:].
+ * Returns the field in [type] described by the given [selector].
+ * If no such field exists, or a subclass overrides the field
+ * returns [:null:].
*/
VariableElement locateSingleField(Type type, Selector selector) {
MemberSet memberSet = _memberSetFor(type, selector);
- int fieldCount = 0;
- int nonFieldCount = 0;
- VariableElement field;
- memberSet.elements.forEach((Element element) {
- if (element.isField()) {
- field = element;
- fieldCount++;
- } else {
- nonFieldCount++;
- }
- });
- return (fieldCount == 1 && nonFieldCount == 0) ? field : null;
+ ClassElement cls = type.element;
+ Element result = cls.lookupSelector(selector);
+ if (result == null) return null;
+ if (!result.isField()) return null;
+
+ // Verify that no subclass overrides the field.
+ if (memberSet.elements.length != 1) return null;
+ assert(memberSet.elements.contains(result));
+ return result;
}
Set<ClassElement> findNoSuchMethodHolders(Type type) {
« no previous file with comments | « no previous file | tests/language/cast2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698