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

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: Fix type annotation. 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') | tests/language/cast2_test.dart » ('J')
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 afef86402415900c9b4bb30aeb5842ffc6543ec1..f8c0519d9f34cf8c1d94c83924412146ebc2fc1e 100644
--- a/lib/compiler/implementation/world.dart
+++ b/lib/compiler/implementation/world.dart
@@ -31,7 +31,7 @@ class World {
/**
* Returns a [MemberSet] that contains the possible targets of a
* selector named [member] accessible from the given [library] on a receiver
- * with the given [type].
+ * with the given [type]. This includes all sub types.
*
* The [library] can be `null` if the [member] is not private.
*/
@@ -58,26 +58,23 @@ class World {
}
/**
- * Returns the single field with the given [name] accessible in the given
- * [library]. If there is no such field, or there are multiple possible
- * fields returns `null`.
+ * Returns the field in [type] with the given [name] accessible in the given
+ * [library]. If no such field exists, or a subclass overrides the field
+ * returns `null`.
*/
VariableElement locateSingleField(Type type,
LibraryElement library,
SourceString name) {
+ ClassElement cls = type.element;
+ Element result = cls.lookupMemberInLibrary(name, library);
+ if (result == null) return null;
+ if (!result.isField()) return null;
+
+ // Verify that no subclass overrides the field.
MemberSet memberSet = _memberSetFor(type, library, name);
- 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;
+ 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') | tests/language/cast2_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698