Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
paxcut opened this issue Jul 18, 2024 · 0 comments

Comments

@paxcut
Copy link
Contributor

paxcut commented Jul 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant