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

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

Issue 8867001: Check for using 'this' and 'super'. Tests. Issue 662. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix for using this/super in field. Tweaks for comments. Created 9 years 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 f838170719921ae22b7b148da1ab3ec41dfd7014..90b9e743ac921a835bb6d49998b4468a6d6c4a59 100644
--- a/compiler/java/com/google/dart/compiler/resolver/Resolver.java
+++ b/compiler/java/com/google/dart/compiler/resolver/Resolver.java
@@ -636,10 +636,14 @@ public class Resolver {
@Override
public Element visitThisExpression(DartThisExpression x) {
- if (currentMethod.getModifiers().isStatic()) {
- onError(x, ResolverErrorCode.STATIC_METHOD_ACCESS_THIS);
- } else if (ElementKind.of(currentHolder).equals(ElementKind.LIBRARY)) {
- onError(x, ResolverErrorCode.TOP_LEVEL_METHOD_ACCESS_THIS);
+ if (ElementKind.of(currentHolder).equals(ElementKind.LIBRARY)) {
+ onError(x, ResolverErrorCode.THIS_ON_TOP_LEVEL);
+ } else if (currentMethod == null) {
+ onError(x, ResolverErrorCode.THIS_OUTSIDE_OF_METHOD);
+ } else if (currentMethod.getModifiers().isStatic()) {
+ onError(x, ResolverErrorCode.THIS_IN_STATIC_METHOD);
+ } else if (currentMethod.getModifiers().isFactory()) {
+ onError(x, ResolverErrorCode.THIS_IN_FACTORY_CONSTRUCTOR);
}
return null;
}
@@ -647,13 +651,13 @@ public class Resolver {
@Override
public Element visitSuperExpression(DartSuperExpression x) {
if (ElementKind.of(currentHolder).equals(ElementKind.LIBRARY)) {
- onError(x, ResolverErrorCode.TOP_LEVEL_METHOD_ACCESS_SUPER);
+ onError(x, ResolverErrorCode.SUPER_ON_TOP_LEVEL);
} else if (currentMethod == null) {
onError(x, ResolverErrorCode.SUPER_OUTSIDE_OF_METHOD);
} else if (currentMethod.getModifiers().isStatic()) {
- onError(x, ResolverErrorCode.STATIC_METHOD_ACCESS_SUPER);
+ onError(x, ResolverErrorCode.SUPER_IN_STATIC_METHOD);
} else if (currentMethod.getModifiers().isFactory()) {
- onError(x, ResolverErrorCode.FACTORY_ACCESS_SUPER);
+ onError(x, ResolverErrorCode.SUPER_IN_FACTORY_CONSTRUCTOR);
} else {
return recordElement(x, Elements.superElement(
x, ((ClassElement) currentHolder).getSupertype().getElement()));

Powered by Google App Engine
This is Rietveld 408576698