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

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

Issue 10532054: Fix for issue 1343 (Closed) Base URL: http://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/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();

Powered by Google App Engine
This is Rietveld 408576698