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

Implement OR match pattern #4348

Merged
merged 15 commits into from
Apr 18, 2023
Merged

Implement OR match pattern #4348

merged 15 commits into from
Apr 18, 2023

Conversation

IGI-111
Copy link
Contributor

@IGI-111 IGI-111 commented Mar 27, 2023

Description

Allow users to specify match patters such as:

let x = 1;
match x {
  0 | 1 => true,
  _ => false
}

We also check that all patterns in a disjunction declare the same set of
variables (not doing so is an error).

Fix #769

This requires a change in the pattern matching analysis to remove the
assumption that a specialized matrix of a vector pattern is always a
vector, which is now no longer true because or patterns can generate
multiple branches and therefore multiple rows.

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@IGI-111 IGI-111 force-pushed the IGI-111/or-match-pattern branch 3 times, most recently from 0b08704 to b0d9a17 Compare March 27, 2023 09:06
@mohammadfawaz mohammadfawaz added compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler: parser Everything to do with the parser labels Apr 6, 2023
@IGI-111 IGI-111 force-pushed the IGI-111/or-match-pattern branch 5 times, most recently from ef3e4b8 to de96d33 Compare April 12, 2023 13:37
@IGI-111 IGI-111 marked this pull request as ready for review April 12, 2023 13:37
@IGI-111 IGI-111 requested review from emilyaherbert, esdrubal, kayagokalp and a team April 12, 2023 13:38
@IGI-111 IGI-111 force-pushed the IGI-111/or-match-pattern branch 4 times, most recently from 92892e3 to a561a3f Compare April 12, 2023 22:54
@IGI-111 IGI-111 force-pushed the IGI-111/or-match-pattern branch from 30b611f to 632d331 Compare April 12, 2023 23:15
Allow users to specify match patters such as:

```sway
let x = 1;
match x {
  0 | 1 => true,
  _ => false
}
```

We also check that all patterns in a disjunction declare the same set of
variables (not doing so is an error).

Fix #769

This requires a change in the pattern matching analysis to remove the
assumption that a specialized matrix of a vector pattern is always a
vector, which is now no longer true because or patterns can generate
multiple branches and therefore multiple rows.
@IGI-111 IGI-111 force-pushed the IGI-111/or-match-pattern branch from 632d331 to 9007612 Compare April 12, 2023 23:27
@IGI-111 IGI-111 requested a review from a team April 12, 2023 23:28
@JoshuaBatty JoshuaBatty requested a review from a team April 13, 2023 00:00
Copy link
Contributor

@tritao tritao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't review the matrix code as I'm not familiar with that part of the code, but everything else lgtm

@JoshuaBatty JoshuaBatty enabled auto-merge (squash) April 18, 2023 21:58
@JoshuaBatty JoshuaBatty merged commit 30f869a into master Apr 18, 2023
@JoshuaBatty JoshuaBatty deleted the IGI-111/or-match-pattern branch April 18, 2023 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler: parser Everything to do with the parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement "or" match patterns in match expressions.
4 participants