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

Unified Diff: compiler/java/com/google/dart/compiler/resolver/Resolver.java

Issue 9307010: Type Variables cannot be used in identifier expressions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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
Index: compiler/java/com/google/dart/compiler/resolver/Resolver.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/Resolver.java b/compiler/java/com/google/dart/compiler/resolver/Resolver.java
index b130ff42a7b401c4791bf108f6d0c407f16eb952..f3492a8fa7143730539be54b478e7017725a638a 100644
--- a/compiler/java/com/google/dart/compiler/resolver/Resolver.java
+++ b/compiler/java/com/google/dart/compiler/resolver/Resolver.java
@@ -1012,28 +1012,7 @@ public class Resolver {
}
}
} else {
- switch (element.getKind()) {
- case FIELD:
- if (inStaticContext(currentMethod) && !inStaticContext(element)) {
- onError(x, ResolverErrorCode.ILLEGAL_FIELD_ACCESS_FROM_STATIC,
- name);
- }
- break;
- case METHOD:
- if (inStaticContext(currentMethod) && !inStaticContext(element)) {
- onError(x, ResolverErrorCode.ILLEGAL_METHOD_ACCESS_FROM_STATIC,
- name);
- }
- break;
- case CLASS:
- if (!isQualifier) {
- onError(x, ResolverErrorCode.IS_A_CLASS, name);
- }
- break;
-
- default:
- break;
- }
+ element = checkResolvedIdentifier(x, isQualifier, scope, name, element);
}
if (inInitializer && (element != null && element.getKind().equals(ElementKind.FIELD))) {
@@ -1048,6 +1027,48 @@ public class Resolver {
return recordElement(x, element);
}
+ /**
+ * Possibly rescursive check on the resolved identifier.
scheglov 2012/01/31 20:56:19 re_s_cursive
+ */
+ private Element checkResolvedIdentifier(DartIdentifier x, boolean isQualifier, Scope scope,
+ String name, Element element) {
+ switch (element.getKind()) {
+ case FIELD:
+ if (inStaticContext(currentMethod) && !inStaticContext(element)) {
+ onError(x, ResolverErrorCode.ILLEGAL_FIELD_ACCESS_FROM_STATIC,
+ name);
+ }
+ break;
+ case METHOD:
+ if (inStaticContext(currentMethod) && !inStaticContext(element)) {
+ onError(x, ResolverErrorCode.ILLEGAL_METHOD_ACCESS_FROM_STATIC,
+ name);
+ }
+ break;
+ case CLASS:
+ if (!isQualifier) {
+ onError(x, ResolverErrorCode.IS_A_CLASS, name);
+ }
+ break;
+ case TYPE_VARIABLE:
+ // Type variables are not legal in identifier expressions, but the type variable
+ // may be hiding a class element.
+ LibraryElement libraryElement = scope.getLibrary();
+ Scope libraryScope = libraryElement.getScope();
+ // dip again at the library level.
+ element = libraryScope.findElement(libraryElement, name);
+ if (element == null) {
+ onError(x, ResolverErrorCode.TYPE_VARIABLE_NOT_ALLOWED_IN_IDENTIFIER);
+ } else {
+ return checkResolvedIdentifier(x, isQualifier, libraryScope, name, element);
+ }
+ break;
+ default:
+ break;
+ }
+ return element;
+ }
+
@Override
public Element visitTypeNode(DartTypeNode x) {
Element result = resolveType(x, inStaticContext(currentMethod), inFactoryContext(currentMethod),

Powered by Google App Engine
This is Rietveld 408576698