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

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

Issue 10831373: Issue 4543. Use complete Resolver before constants analyzer (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
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 852199b4e43d584489fe4b454e4d89b5de14027f..1b46572c8ea2571f34651e516c13c45793ff2120 100644
--- a/compiler/java/com/google/dart/compiler/resolver/Resolver.java
+++ b/compiler/java/com/google/dart/compiler/resolver/Resolver.java
@@ -184,6 +184,7 @@ public class Resolver {
private EnclosingElement currentHolder;
private EnclosingElement enclosingElement;
private MethodElement currentMethod;
+ private boolean inInstanceVariableInitializer;
private boolean inInitializer;
private MethodElement innermostFunction;
private ResolutionContext context;
@@ -662,7 +663,12 @@ public class Resolver {
boolean isStatic = modifiers.isStatic();
if (expression != null) {
- resolve(expression);
+ inInstanceVariableInitializer = !isTopLevel;
+ try {
+ resolve(expression);
+ } finally {
+ inInstanceVariableInitializer = false;
+ }
// Now, this constant has a type. Save it for future reference.
Element element = node.getElement();
Type expressionType = expression.getType();
@@ -1095,9 +1101,12 @@ public class Resolver {
String name, Element element) {
switch (element.getKind()) {
case FIELD:
- if (inStaticContext(currentMethod) && !inStaticContext(element)) {
- onError(x, ResolverErrorCode.ILLEGAL_FIELD_ACCESS_FROM_STATIC,
- name);
+ if (!inStaticContext(element)) {
+ if (inInstanceVariableInitializer) {
+ onError(x, ResolverErrorCode.CANNOT_USE_INSTANCE_FIELD_IN_INSTANCE_FIELD_INITIALIZER);
+ } else if (inStaticContext(currentMethod)) {
+ onError(x, ResolverErrorCode.ILLEGAL_FIELD_ACCESS_FROM_STATIC, name);
+ }
}
if (isIllegalPrivateAccess(x, enclosingElement, element, x.getName())) {
return null;
@@ -2151,8 +2160,8 @@ public class Resolver {
}
private boolean inStaticContext(Element element) {
- return element == null || Elements.isTopLevel(element)
- || element.getModifiers().isStatic() || element.getModifiers().isFactory();
+ return element == null || Elements.isTopLevel(element) || element.getModifiers().isStatic()
+ || element.getModifiers().isConstant() || element.getModifiers().isFactory();
}
@Override

Powered by Google App Engine
This is Rietveld 408576698