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

Unified Diff: frog/parser.dart

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 | « frog/minfrog ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/parser.dart
diff --git a/frog/parser.dart b/frog/parser.dart
index c4dd83bb72cbcb5197bdc311cc7fb4117dbe0a42..483611bacd6342abf26a601768cac9da828ff9c2 100644
--- a/frog/parser.dart
+++ b/frog/parser.dart
@@ -1456,14 +1456,21 @@ class Parser {
return finishListLiteral(start, isConst, genericType);
} else if (_peekKind(TokenKind.LBRACE)) {
genericType.baseType = new TypeReference(span, world.mapType);
- if (genericType.typeArguments.length != 1) {
- _error('a map literal takes one type argument specfying the value type',
- genericType.typeArguments.length == 0
- ? genericType.typeArguments.span
- : genericType.typeArguments[1].span);
- }
- genericType.typeArguments = [new TypeReference(span, world.stringType),
- genericType.typeArguments[0]];
+ if (genericType.typeArguments.length == 1) {
+ genericType.typeArguments = [new TypeReference(span, world.stringType),
+ genericType.typeArguments[0]];
+ } else if (genericType.typeArguments.length == 2) {
+ var keyType = genericType.typeArguments[0];
+ if (keyType is! NameTypeReference || keyType.name.name !== "String") {
+ world.error('the key type of a map literal is implicitly "String"',
+ keyType.span);
+ } else {
+ // making key explicit is just a warning.
+ world.warning(
+ 'a map literal takes one type argument specifying the value type',
+ keyType.span);
+ }
+ } // o.w. the type system will detect the mismatch in type arguments.
return finishMapLiteral(start, isConst, genericType);
} else {
_errorExpected('array or map literal');
« no previous file with comments | « frog/minfrog ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698