dart-lang / dart-lang/language
[Pattern-matching] Allow :name syntax in switch statements
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
There's a shorthand syntax in object matching

I tried to use it in switch statements and expected it will work.
My expectation: `Data()` will be destructured and its `name` parameter will be binded to a corresponding new `name` variable automatically.
but it fails with following errors:
It works only if I use an explicit syntax
But it looks excessive.
It also ain't working in switch expressions:
## Proposal: ##
Allow using the `:name` syntax in object matching in switch statements and switch expressions
Contributor guide
Research direction
Start by reviewing the object-matching examples and the reported failures in switch statements and switch expressions. Compare the proposed :name shorthand with the explicit syntax shown in the issue, then determine the language-specification changes needed for destructuring and binding. Done means the shorthand has defined behavior and works consistently in both switch forms.
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
- 30/100