dart-lang / dart-lang/language
Replace record fields (`$1`, `$2`, etc.) with named fields if type contains field names (eg. `(int a, int b)`)
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Given the declaration
```dart
(int a, int b) v = (1, 2);
```
you can access `v.$1` and `v.$2`, but I would have expected to be able to access `v.a` and `v.b` (these fields don't exist).
I would expect `$1` and `$2` to not be visible or usable for the type `(int a, int b)`, since there shouldn't be two ways to access the same value.
I would only expect to have to use `$1` and `$2` if the fields were not named, e.g.:
```dart
(int, int) v = (1, 2);
```
@mraleph stated in another issue (which I branched this separate issue out from):
> The choice of names not having any meaning was deliberate, but I don't see any reason why it would not work to just allow this in a statically typed context (i.e. ignoring dynamic invocations entirely).
Contributor guide
Research direction
Start with the record declarations and access examples in this issue, then read the referenced discussion about allowing named access only in statically typed contexts. There are no files or tests identified in the payload; done would require an agreed language-design resolution for named versus positional record-field access, including the stated dynamic-invocation caveat.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100