|
1 | 1 | # Set Literals Design Document
|
2 | 2 | Author: lrn@google.com
|
| 3 | +Version: 1.1 |
3 | 4 |
|
4 | 5 | Solution for [Set Literals Problem](http://github.com/dart-lang/language/issues/36).
|
5 | 6 | Based on feature proposal [Issue 37](http://github.com/dart-lang/language/issues/37)
|
@@ -84,12 +85,14 @@ if *s* has a `typeArguments` with two type arguments, *s* is a *map literal*.
|
84 | 85 | (*Three or more type arguments is a compile time error, so the remaining possible case is having no type arguments*).
|
85 | 86 |
|
86 | 87 | If *s* is an `emptySetOrMapLiteral` with no `typeArguments` and static context type *C*, then
|
87 |
| -if `Set<Null>` is assignable to *C* and `Map<Null, Null>` is not assignable to *C*, then *s* is a *set literal*, |
88 |
| -otherwise *s* is a *map literal*. |
| 88 | +if `LinkedHashSet<Null>` is assignable to *C* and `LinkedHashMap<Null, Null>` is not assignable to *C*, |
| 89 | +then *s* is a *set literal*, otherwise *s* is a *map literal*. |
89 | 90 |
|
90 |
| -(*So if *C* is, for example, `Iterable<int>` or `Set<Object>` or `FutureOr<Iterable<int>>` or a type variable with any of |
91 |
| -those as bound, then *s* is a set literal. If *C* is `Object` or `dynamic` or `Null` or `String`, then *s* is a map literal, |
92 |
| -*and* potentially a compile-time error due to static typing*). |
| 91 | +(*So if *C* is, for example, `Iterable<int>`, `Set<Object>`, `LinkedHashSet<int>` or `FutureOr<Iterable<int>>`, |
| 92 | +then *s* is a set literal. If *C* is `Object` or `dynamic` or `Null` or `String`, then *s* is a map literal, |
| 93 | +*and* potentially a compile-time error due to static typing*. If *C* is some subclass of `Set<X>` other than `LinkedHashSet`, then the literal is a map literal, but it is also a guaranteed type error even if the literal |
| 94 | +is a set. If *C* is a subtype of `LinkedHashSet<X>` *and* a subtype of `LinkedHashMap<Y, Z>`, then *s* is again |
| 95 | +a map literal, and a guaranteed run-time type error). |
93 | 96 |
|
94 | 97 | ### Map literals
|
95 | 98 |
|
@@ -357,3 +360,7 @@ var s6 = {...{1: 1}, ...?d}; // Map<dynamic, dynamic>
|
357 | 360 | // var s7 = {...?d}; // Compile-time error, ambiguous
|
358 | 361 | // var s8 = {...{1}, ...{1: 1}}; // Compile-time error, incompatible
|
359 | 362 | ```
|
| 363 | + |
| 364 | +##Revisions |
| 365 | +1.0: Initial version plus type fixes. |
| 366 | +1.1: Changed type rules for selecting set literals over map literals. |
0 commit comments