Skip to content

Change type requirements for {} being a set literal. #129

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Dec 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions accepted/future-releases/set-literals/feature-specification.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Set Literals Design Document
Author: lrn@google.com
Version: 1.1

Solution for [Set Literals Problem](http://github.com/dart-lang/language/issues/36).
Based on feature proposal [Issue 37](http://github.com/dart-lang/language/issues/37)
Expand Down Expand Up @@ -84,12 +85,14 @@ if *s* has a `typeArguments` with two type arguments, *s* is a *map literal*.
(*Three or more type arguments is a compile time error, so the remaining possible case is having no type arguments*).

If *s* is an `emptySetOrMapLiteral` with no `typeArguments` and static context type *C*, then
if `Set<Null>` is assignable to *C* and `Map<Null, Null>` is not assignable to *C*, then *s* is a *set literal*,
otherwise *s* is a *map literal*.
if `LinkedHashSet<Null>` is assignable to *C* and `LinkedHashMap<Null, Null>` is not assignable to *C*,
then *s* is a *set literal*, otherwise *s* is a *map literal*.

(*So if *C* is, for example, `Iterable<int>` or `Set<Object>` or `FutureOr<Iterable<int>>` or a type variable with any of
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,
*and* potentially a compile-time error due to static typing*).
(*So if *C* is, for example, `Iterable<int>`, `Set<Object>`, `LinkedHashSet<int>` or `FutureOr<Iterable<int>>`,
then *s* is a set literal. If *C* is `Object` or `dynamic` or `Null` or `String`, then *s* is a map literal,
*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
is a set. If *C* is a subtype of `LinkedHashSet<X>` *and* a subtype of `LinkedHashMap<Y, Z>`, then *s* is again
a map literal, and a guaranteed run-time type error).

### Map literals

Expand Down Expand Up @@ -357,3 +360,7 @@ var s6 = {...{1: 1}, ...?d}; // Map<dynamic, dynamic>
// var s7 = {...?d}; // Compile-time error, ambiguous
// var s8 = {...{1}, ...{1: 1}}; // Compile-time error, incompatible
```

##Revisions
1.0: Initial version plus type fixes.
1.1: Changed type rules for selecting set literals over map literals.