dart-lang / dart-lang/language
Should constant matchers be value matchers
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
See pattern proposal.
The constant matcher can be used to match specific values. It must be a constant value. This makes sense for when it's used in a switch case matcher where we currently require expressions to be constant, but not necessarily in a more dynamic check like e is matcher.
Example:
Iterable<List<T>> listsWhichStartWith<T>(T value, Iterable<List<T>> lists) sync* {
for (var p in lists) if (p is [value, ... var rest]) yield rest;
}
(assuming the List rest-matcher TODO)
If we only allow constant values to be used as matchers, we won't be able to do parameterized pattern matching on provided values. I think we should allow that. Not necessarily in switch, but in is and as checks.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked patterns feature specification, especially the constant-matcher section, and compare it with the issue's parameterized matching example. Determine how constant and value matchers should behave in switch cases versus is and as checks; done means the language specification has a clear decision covering those contexts.
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
- 25/100