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

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

Issue 10991064: Issue 5350. Type variable should be accessible in instance field (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 339805f1a837c16fde60e0858542902fc23dff3d..305df319fb5e3f34880fd2e4730f243f3a1ccb7c 100644
--- a/compiler/java/com/google/dart/compiler/resolver/Resolver.java
+++ b/compiler/java/com/google/dart/compiler/resolver/Resolver.java
@@ -20,7 +20,6 @@ import com.google.dart.compiler.ast.DartBreakStatement;
import com.google.dart.compiler.ast.DartCase;
import com.google.dart.compiler.ast.DartCatchBlock;
import com.google.dart.compiler.ast.DartClass;
-import com.google.dart.compiler.ast.DartClassMember;
import com.google.dart.compiler.ast.DartContinueStatement;
import com.google.dart.compiler.ast.DartDirective;
import com.google.dart.compiler.ast.DartDoWhileStatement;
@@ -696,7 +695,7 @@ public class Resolver {
{
DartTypeNode rcTypeName = node.getRedirectedTypeName();
if (rcTypeName != null) {
- InterfaceType rcType = (InterfaceType) resolveType(rcTypeName, true, true, false,
+ Type rcType = resolveType(rcTypeName, true, true, false,
TypeErrorCode.NO_SUCH_TYPE, ResolverErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS);
switch (TypeKind.of(rcType)) {
case INTERFACE:
@@ -715,6 +714,8 @@ public class Resolver {
}
}
break;
+ default:
+ onError(rcTypeName, ResolverErrorCode.REDIRECTION_CONSTRUCTOR_TARGET_TYPE);
}
}
}
@@ -827,8 +828,8 @@ public class Resolver {
Type type =
resolveType(
node.getTypeNode(),
- inStaticContext(currentMethod),
- inFactoryContext(currentMethod),
+ ASTNodes.isStaticContext(node),
+ ASTNodes.isFactoryContext(node),
true,
TypeErrorCode.NO_SUCH_TYPE,
TypeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS);
@@ -1190,7 +1191,7 @@ public class Resolver {
name, referencedElementName);
}
}
- if (isStaticContextOrInitializer() && !isQualifier) {
+ if (isStaticOrFactoryContextOrInitializer(x) && !isQualifier) {
onError(x, ResolverErrorCode.CANNOT_BE_RESOLVED, name);
x.markResolutionAlreadyReportedThatTheMethodCouldNotBeFound();
}
@@ -1247,10 +1248,10 @@ public class Resolver {
String name, Element element) {
switch (element.getKind()) {
case FIELD:
- if (!inStaticContext(element)) {
+ if (!Elements.isStaticContext(element) && !element.getModifiers().isConstant()) {
if (inInstanceVariableInitializer) {
onError(x, ResolverErrorCode.CANNOT_USE_INSTANCE_FIELD_IN_INSTANCE_FIELD_INITIALIZER);
- } else if (inStaticContext(currentMethod)) {
+ } else if (ASTNodes.isStaticContext(x)) {
onError(x, ResolverErrorCode.ILLEGAL_FIELD_ACCESS_FROM_STATIC, name);
}
}
@@ -1259,7 +1260,7 @@ public class Resolver {
}
break;
case METHOD:
- if (inStaticContext(currentMethod) && !inStaticContext(element)) {
+ if (ASTNodes.isStaticContext(x) && !Elements.isStaticContext(element)) {
onError(x, ResolverErrorCode.ILLEGAL_METHOD_ACCESS_FROM_STATIC,
name);
}
@@ -1317,7 +1318,7 @@ public class Resolver {
}
}
// do Type resolve
- return resolveType(x, inStaticContext(currentMethod), inFactoryContext(currentMethod), false,
+ return resolveType(x, ASTNodes.isStaticContext(x), ASTNodes.isFactoryContext(x), false,
errorCode, wrongNumberErrorCode).getElement();
}
@@ -1572,7 +1573,7 @@ public class Resolver {
}
if (Elements.isAbstractFieldWithoutGetter(element)) {
String name = element.getName();
- if (isStaticContextOrInitializer()) {
+ if (isStaticOrFactoryContextOrInitializer(x)) {
onError(x.getTarget(), ResolverErrorCode.USE_ASSIGNMENT_ON_SETTER, name);
} else {
onError(x.getTarget(), TypeErrorCode.USE_ASSIGNMENT_ON_SETTER, name);
@@ -1600,8 +1601,8 @@ public class Resolver {
@Override
public Element visitTypeNode(DartTypeNode type) {
ErrorCode errorCode = x.isConst() ? ResolverErrorCode.NO_SUCH_TYPE_CONST : TypeErrorCode.NO_SUCH_TYPE;
- return recordType(type, resolveType(type, inStaticContext(currentMethod),
- inFactoryContext(currentMethod),
+ return recordType(type, resolveType(type, ASTNodes.isStaticContext(x),
+ ASTNodes.isFactoryContext(x),
false,
errorCode,
ResolverErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS));
@@ -1855,7 +1856,7 @@ public class Resolver {
ElementKind kind = ElementKind.of(element);
switch (kind) {
case NONE:
- if (isStaticContextOrInitializer()) {
+ if (isStaticOrFactoryContextOrInitializer(node) || ASTNodes.isFactoryContext(node)) {
node.getTarget().markResolutionAlreadyReportedThatTheMethodCouldNotBeFound();
onError(node.getTarget(), ResolverErrorCode.CANNOT_RESOLVE_METHOD, name);
}
@@ -2114,8 +2115,8 @@ public class Resolver {
defaultLiteralMapType.getElement(),
node,
typeArgs,
- inStaticContext(node),
- inFactoryContext(currentMethod),
+ ASTNodes.isStaticContext(node),
+ ASTNodes.isFactoryContext(node),
ResolverErrorCode.NO_SUCH_TYPE,
ResolverErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS);
// instantiateParametersType() will complain for wrong number of parameters (!=2)
@@ -2135,8 +2136,8 @@ public class Resolver {
rawArrayType.getElement(),
node,
typeArgs,
- inStaticContext(node),
- inFactoryContext(currentMethod),
+ ASTNodes.isStaticContext(node),
+ ASTNodes.isFactoryContext(node),
ResolverErrorCode.NO_SUCH_TYPE,
ResolverErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS);
// instantiateParametersType() will complain for wrong number of parameters (!=1)
@@ -2319,42 +2320,8 @@ public class Resolver {
context.onError(target, errorCode, arguments);
}
- private boolean inStaticContext(DartNode node) {
- DartNode ancestor = node;
- while (ancestor != null) {
- if (ancestor instanceof DartClassMember<?>) {
- return ((DartClassMember<?>) ancestor).getModifiers().isStatic();
- }
- ancestor = ancestor.getParent();
- }
- return true;
- }
-
-
- private boolean inFactoryContext(Element element) {
- if (element != null) {
- return element.getModifiers().isFactory();
- }
- return false;
- }
-
- @Override
- boolean isStaticContext() {
- return inStaticContext(currentMethod);
- }
-
- private boolean inStaticContext(Element element) {
- return element == null || Elements.isTopLevel(element) || element.getModifiers().isStatic()
- || element.getModifiers().isConstant() || element.getModifiers().isFactory();
- }
-
- @Override
- boolean isFactoryContext() {
- return inFactoryContext(currentMethod);
- }
-
- boolean isStaticContextOrInitializer() {
- return inStaticContext(currentMethod) || inInitializer;
+ boolean isStaticOrFactoryContextOrInitializer(DartNode x) {
+ return ASTNodes.isStaticOrFactoryContext(x) || inInitializer;
}
}

Powered by Google App Engine
This is Rietveld 408576698