Allow multiple parameters for the [] and []= operators. #8980
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
closed-duplicate
Closed in favor of an existing report
type-enhancement
A request for a change that isn't a bug
We could allow multiple parameters on the [] and []= operators, e.g.,
That would allow multi-dimensional lookups and assignments with a good-looking syntax. Usage would be the expected:
Using the wrong number of parameters for an object would be a noSuchMethod call, just as for a similar methods.
The alternative is to write "get" and "set" methods, which isn't as readable.
The necessary grammar changes is to allow the same arguments between [] as between () in a call, and relax the requirements on arguments for operator[] and operator[]=.
I put the value of operator[] first, so that it's possible to use named parameters, e.g.
foo[x:42, y:12] = 10
.We can also disallow optional parameters to begin with.
(This was not my idea, but I liked it when I heard it!)
The text was updated successfully, but these errors were encountered: