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

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

Issue 11369050: Issue 6489. Report error when static method attempts to access const instance field. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 35bc6619e6a6bf849d044f24cde331870a9baf0c..9974915e42728d147fef43ae1dd708d88881e87b 100644
--- a/compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java
+++ b/compiler/java/com/google/dart/compiler/resolver/CompileTimeConstantAnalyzer.java
@@ -68,12 +68,6 @@ import java.util.Set;
public class CompileTimeConstantAnalyzer {
private class ExpressionVisitor extends ASTVisitor<Void> {
- private final boolean shouldBeStatic;
-
- private ExpressionVisitor(boolean shouldBeStatic) {
- this.shouldBeStatic = shouldBeStatic;
- }
-
private boolean checkBoolean(DartNode x, Type type) {
// Spec 0.11 allows using "null" literal in place of bool.
if (x instanceof DartNullLiteral) {
@@ -381,11 +375,6 @@ public class CompileTimeConstantAnalyzer {
case FIELD:
FieldElement fieldElement = (FieldElement) element;
- if (shouldBeStatic && !elementIsStatic) {
- context.onError(new DartCompilationError(x, ResolverErrorCode.NOT_A_STATIC_FIELD,
- fieldElement.getName()));
- }
-
// Check for circular references.
if (element != null && visitedElements.contains(element)) {
context.onError(new DartCompilationError(x, ResolverErrorCode.CIRCULAR_REFERENCE));
@@ -638,7 +627,7 @@ public class CompileTimeConstantAnalyzer {
public Void visitField(DartField node) {
if (node.getParent() != null) {
if (node.getModifiers().isConstant()) {
- Type type = checkConstantExpression(node.getValue(), node.getModifiers().isStatic());
+ Type type = checkConstantExpression(node.getValue());
if (node.getElement().getType().equals(dynamicType)) {
node.getElement().setConstantType(type);
}
@@ -797,12 +786,8 @@ public class CompileTimeConstantAnalyzer {
}
private Type checkConstantExpression(DartExpression expression) {
- return checkConstantExpression(expression, false);
- }
-
- private Type checkConstantExpression(DartExpression expression, boolean shouldBeStatic) {
if (expression != null) {
- ExpressionVisitor visitor = new ExpressionVisitor(shouldBeStatic);
+ ExpressionVisitor visitor = new ExpressionVisitor();
expression.accept(visitor);
return visitor.getMostSpecificType(expression);
}

Powered by Google App Engine
This is Rietveld 408576698