dart-lang / dart-lang/language

Should constant matchers be value matchers

Open
#1,406 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

patterns
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.