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

Unified Diff: frog/minfrog

Issue 8856004: frog: better errors/warnigns about type annotations in map literals. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' 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
« no previous file with comments | « client/html/src/EventTargetWrappingImplementation.dart ('k') | frog/parser.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/minfrog
diff --git a/frog/minfrog b/frog/minfrog
index 83014efdea4fed57280c833a7191eb68668f6a71..fec609826d29be4a02772d8042a32a80cbafdd70 100755
--- a/frog/minfrog
+++ b/frog/minfrog
@@ -9383,10 +9383,18 @@ Parser.prototype.finishTypedLiteral = function(start, isConst) {
}
else if (this._peekKind(6/*TokenKind.LBRACE*/)) {
genericType.set$baseType(new TypeReference(span, $globals.world.mapType));
- if ($ne(genericType.get$typeArguments().length, 1)) {
- this._error('a map literal takes one type argument specfying the value type', $eq(genericType.get$typeArguments().length, 0) ? genericType.get$typeArguments().get$span() : genericType.get$typeArguments().$index(1).get$span());
+ if ($eq(genericType.get$typeArguments().length, 1)) {
+ genericType.set$typeArguments([new TypeReference(span, $globals.world.stringType), genericType.get$typeArguments().$index(0)]);
+ }
+ else if ($eq(genericType.get$typeArguments().length, 2)) {
+ var keyType = genericType.get$typeArguments().$index(0);
+ if (!(keyType instanceof NameTypeReference) || keyType.get$name().get$name() !== "String") {
+ $globals.world.error('the key type of a map literal is implicitly "String"', keyType.get$span());
+ }
+ else {
+ $globals.world.warning('a map literal takes one type argument specifying the value type', keyType.get$span());
+ }
}
- genericType.set$typeArguments([new TypeReference(span, $globals.world.stringType), genericType.get$typeArguments().$index(0)]);
return this.finishMapLiteral(start, isConst, genericType);
}
else {
« no previous file with comments | « client/html/src/EventTargetWrappingImplementation.dart ('k') | frog/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698