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

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

Issue 10542098: Issue 3404. Static & top level functions are constant (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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/CompileTimeConstantAnalyzer.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java b/compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java
index 35abfc85661c703c14b1b5cf1b3a20f748da420d..137841f31cb0e9635c1ac1c0ddb4caae378b2464 100644
--- a/compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java
@@ -359,9 +359,14 @@ public class CompileTimeConstantAnalyzer {
rememberInferredType(x, inferredType);
break;
+
+ case METHOD:
+ if (!element.getModifiers().isStatic() && !Elements.isTopLevel(element)) {
+ expectedConstant(x);
+ }
+ return null;
case NONE:
- case METHOD:
expectedConstant(x);
return null;
@@ -429,7 +434,6 @@ public class CompileTimeConstantAnalyzer {
@Override
public Void visitPropertyAccess(DartPropertyAccess x) {
- x.visitChildren(this);
switch (ElementKind.of(x.getQualifier().getElement())) {
case CLASS:
case LIBRARY_PREFIX:
@@ -442,9 +446,20 @@ public class CompileTimeConstantAnalyzer {
}
Element element = x.getName().getElement();
- if (element != null && !element.getModifiers().isConstant()) {
+ while (element != null) {
+ // OK. Static method reference.
+ if (ElementKind.of(element) == ElementKind.METHOD && element.getModifiers().isStatic()) {
+ break;
+ }
+ // OK. Constant field.
+ if (element.getModifiers().isConstant()) {
+ break;
+ }
+ // Fail.
expectedConstant(x);
+ return null;
}
+ x.visitChildren(this);
Type type = getMostSpecificType(x.getName());
rememberInferredType(x, type);
return null;

Powered by Google App Engine
This is Rietveld 408576698