Chromium Code Reviews| Index: compiler/java/com/google/dart/compiler/resolver/Resolver.java |
| =================================================================== |
| --- compiler/java/com/google/dart/compiler/resolver/Resolver.java (revision 8407) |
| +++ compiler/java/com/google/dart/compiler/resolver/Resolver.java (working copy) |
| @@ -17,6 +17,7 @@ |
| import com.google.dart.compiler.ast.DartBreakStatement; |
| 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.DartDoWhileStatement; |
| import com.google.dart.compiler.ast.DartDoubleLiteral; |
| import com.google.dart.compiler.ast.DartExpression; |
| @@ -1694,14 +1695,17 @@ |
| } |
| InterfaceType type = |
| - topLevelContext.instantiateParameterizedType( |
| + context.instantiateParameterizedType( |
| defaultLiteralMapType.getElement(), |
| node, |
| typeArgs, |
| - inStaticContext(currentMethod), |
| + inStaticContext(node), |
| inFactoryContext(currentMethod), |
| ResolverErrorCode.NO_SUCH_TYPE); |
| // instantiateParametersType() will complain for wrong number of parameters (!=2) |
| + if (node.isConst()) { |
| + checkTypeArgumentsInConstLiteral(typeArgs, ResolverErrorCode.CONST_MAP_WITH_TYPE_VARIABLE); |
| + } |
| recordType(node, type); |
| visit(node.getEntries()); |
| return null; |
| @@ -1711,19 +1715,31 @@ |
| public Element visitArrayLiteral(DartArrayLiteral node) { |
| List<DartTypeNode> typeArgs = node.getTypeArguments(); |
| InterfaceType type = |
| - topLevelContext.instantiateParameterizedType( |
| + context.instantiateParameterizedType( |
| rawArrayType.getElement(), |
| node, |
| typeArgs, |
| - inStaticContext(currentMethod), |
| + inStaticContext(node), |
| inFactoryContext(currentMethod), |
| ResolverErrorCode.NO_SUCH_TYPE); |
| // instantiateParametersType() will complain for wrong number of parameters (!=1) |
| + if (node.isConst()) { |
| + checkTypeArgumentsInConstLiteral(typeArgs, ResolverErrorCode.CONST_ARRAY_WITH_TYPE_VARIABLE); |
| + } |
| recordType(node, type); |
| visit(node.getExpressions()); |
| return null; |
| } |
| + private void checkTypeArgumentsInConstLiteral(List<DartTypeNode> typeArgs, ErrorCode errorCode) { |
| + for (DartTypeNode typeNode : typeArgs) { |
| + Type type = typeNode.getType(); |
| + if (type != null && type.getKind() == TypeKind.VARIABLE) { |
| + onError(typeNode, errorCode); |
| + } |
| + } |
| + } |
| + |
| private ConstructorElement checkIsConstructor(DartNewExpression source, Element element) { |
| if (!ElementKind.of(element).equals(ElementKind.CONSTRUCTOR)) { |
| onError(source.getConstructor(), ResolverErrorCode.NEW_EXPRESSION_NOT_CONSTRUCTOR); |
| @@ -1819,6 +1835,17 @@ |
| context.onError(node, errorCode, arguments); |
| } |
| + private boolean inStaticContext(DartNode node) { |
| + DartNode anscestor = node; |
|
zundel
2012/06/07 21:11:19
typo: anscestor -> ancestor
Brian Wilkerson
2012/06/07 21:19:05
Done
|
| + while (anscestor != null) { |
| + if (anscestor instanceof DartClassMember<?>) { |
| + return ((DartClassMember<?>) anscestor).getModifiers().isStatic(); |
| + } |
| + anscestor = anscestor.getParent(); |
| + } |
| + return true; |
| + } |
| + |
| private boolean inStaticContext(Element element) { |
| return element == null || Elements.isTopLevel(element) |
| || element.getModifiers().isStatic() || element.getModifiers().isFactory(); |