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

Unified Diff: frog/gen.dart

Issue 8849001: frog: use type annotation in map and list 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
Index: frog/gen.dart
diff --git a/frog/gen.dart b/frog/gen.dart
index e16cae92da7609585af2af62cbc35fe1aa41bb0c..4fe8d0893e66e2360063f62a0a043f489520ffda 100644
--- a/frog/gen.dart
+++ b/frog/gen.dart
@@ -2147,8 +2147,16 @@ class MethodGenerator implements TreeVisitor {
// TODO(jimhug): Use node.type or other type inference here.
var argsCode = [];
var argValues = [];
+ var type = null;
+ if (node.type !== null) {
+ // The parser makes node.type a list type, we extract its type argument.
+ type = method.resolveType(node.type, true).typeArgsInOrder[0];
+ if (node.isConst && (type is ParameterType || type.hasTypeParams)) {
+ world.error('type parameter cannot be used in const list literals');
+ }
+ }
for (var item in node.values) {
- var arg = visitValue(item);
+ var arg = type === null ? visitValue(item) : visitTypedValue(item, type);
Jennifer Messerly 2011/12/08 02:13:26 I'd move this check into visitTypedValue. Especial
Siggi Cherem (dart-lang) 2011/12/08 23:02:15 Done
argValues.add(arg);
if (node.isConst) {
if (!arg.isConst) {
@@ -2189,12 +2197,22 @@ class MethodGenerator implements TreeVisitor {
var argValues = [];
var argsCode = [];
+ var type = null;
+ if (node.type !== null) {
+ // node.type is a map type, extract the type argument for the values.
+ type = method.resolveType(node.type, true).typeArgsInOrder[1];
+ if (node.isConst && (type is ParameterType || type.hasTypeParams)) {
+ world.error('type parameter cannot be used in const map literals');
+ }
+ }
for (int i = 0; i < node.items.length; i += 2) {
// TODO(jimhug): Use node.type or other type inference here.
- // TODO(jimhug): Would be nice to allow arbitrary keys here.
+ // TODO(jimhug): Would be nice to allow arbitrary keys here (this is
+ // currently not allowed by the spec).
var key = visitTypedValue(node.items[i], world.stringType);
final valueItem = node.items[i+1];
- var value = visitValue(valueItem);
+ var value = type === null ? visitValue(valueItem)
+ : visitTypedValue(valueItem, type);
argValues.add(key);
argValues.add(value);

Powered by Google App Engine
This is Rietveld 408576698