Chromium Code Reviews| Index: runtime/vm/parser.cc |
| =================================================================== |
| --- runtime/vm/parser.cc (revision 10854) |
| +++ runtime/vm/parser.cc (working copy) |
| @@ -8067,29 +8067,27 @@ |
| // equivalent to using Dynamic as the type argument for the value type. |
| if (!map_type_arguments.IsNull()) { |
| ASSERT(map_type_arguments.Length() > 0); |
| - // Map literals take a single type argument. |
| - value_type = map_type_arguments.TypeAt(0); |
| - if (map_type_arguments.Length() > 1) { |
| - // We temporarily accept two type arguments, as long as the first one is |
| - // type String. |
| - if (map_type_arguments.Length() != 2) { |
| - ErrorMsg(type_pos, |
| - "a map literal takes one type argument specifying " |
| - "the value type"); |
| - } |
| - if (!value_type.IsStringInterface()) { |
| - ErrorMsg(type_pos, |
| - "the key type of a map literal is implicitly 'String'"); |
| - } |
| + // Map literals take two type arguments. |
| + if (map_type_arguments.Length() < 2) { |
| + // We temporarily accept a single type argument. |
| Warning(type_pos, |
|
hausner
2012/08/16 20:02:39
As Peter notes, I would guard this with a separate
regis
2012/08/16 20:11:00
Done. I have hidden the warning behind --warn_lega
|
| - "a map literal takes one type argument specifying " |
| - "the value type"); |
| - value_type = map_type_arguments.TypeAt(1); |
| - } else { |
| + "a map literal takes two type arguments specifying " |
| + "the key type and the value type"); |
| TypeArguments& type_array = TypeArguments::Handle(TypeArguments::New(2)); |
| type_array.SetTypeAt(0, Type::Handle(Type::StringInterface())); |
| type_array.SetTypeAt(1, value_type); |
| map_type_arguments = type_array.raw(); |
| + } else if (map_type_arguments.Length() > 2) { |
| + ErrorMsg(type_pos, |
| + "a map literal takes two type arguments specifying " |
| + "the key type and the value type"); |
| + } else { |
| + const AbstractType& key_type = |
| + AbstractType::Handle(map_type_arguments.TypeAt(0)); |
| + value_type = map_type_arguments.TypeAt(1); |
| + if (!key_type.IsStringInterface()) { |
| + ErrorMsg(type_pos, "the key type of a map literal must be 'String'"); |
| + } |
| } |
| if (is_const && !value_type.IsInstantiated()) { |
| ErrorMsg(type_pos, |