dart-lang / dart-lang/language
Allow a destructuring context in matching patterns
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
It would be nice to be able to switch from a matching context to a destructuring context within a pattern, particularly when dealing with records or objects for which you're assigning multiple values at once. I propose the syntax `var [pattern]` be allowed anywhere in a matching pattern, where the inner pattern is treated as a destructuring pattern instead.
For example,
```dart
case var (:operand, :left, :right):
```
would be equivalent to
```dart
case (:var operand, :var left, :var right):
```
This mirrors the existing variable declaration syntax, in which `var` introduces a destructuring pattern at statement level.
Contributor guide
Research direction
The issue names no files, tests, or entry points. Start by locating the Dart language specification sections covering matching and destructuring patterns, then trace how statement-level var patterns are specified. Done means the proposed syntax and its equivalence are resolved in the specification, with any required tests identified.
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
- Mostly clear
- Newbie friendliness
- 35/100