WerWolv / WerWolv/PatternLanguage

Default case `_` on match statements reverts to regular wildcard when more than one variable is being checked.

Open
#114 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
275
Forks
75
Avg merge
1d 22h
Merged PRs (30d)
10

Description

In a match statement the case _ stands for all the remaining values not yet considered. This works fine when only one expression is being matched.If there is more than one expression then the pattern language incorrectly treats _ as a "any value" wildcard which in turn creates errors when there are none. The simplest example is perhaps something like

u8 N = 4;
match (N) {
    (4) : result = 2;
    (_) : result = 44;
}

The first case tests if value is 4 and the second case matches any value except 4. Thus no ambiguities exist because the cases are mutually exclusive and in this case result will become 2. Consider now the similarly looking match statement that is

u8 M = 5;
match (M,N) {
    (5,4) : result = 2;
    (5,_) : result = 44;
    (_,4) : result = 55;
    (_,_) : result = 66;
}

which prints error messages stating that cases 1 and 2 are ambiguous erroneously. the fist case case checks if M is 5 and N is 4 and the second case should be checking if M is 5 and N is not 4 but instead it is checking for M being 5 and N being any value which would be ambiguous with first case.
The reason I can say with confidence that there is a bug here is that the match statement is an operation brought into the pattern language from rust and running the two matches in rust sets result to be 2 and there are no ambiguity errors

Contributor guide

No contributing guide indexed for this repository

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 by reproducing the two match examples from the issue and inspect the match-pattern handling and ambiguity checks in the Pattern Language implementation. Compare the behavior of _ in single- and multiple-expression matches; done means the tuple cases are no longer reported as ambiguous and select the intended result.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.