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

Invalid error message that variable is not bound in all match arm alternatives in case of duplicates in alternatives #5082

Closed
ironcev opened this issue Sep 2, 2023 · 0 comments · Fixed by #5104
Assignees
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler: static-analysis compiler General compiler. Should eventually become more specific as the issue is triaged

Comments

@ironcev
Copy link
Member

ironcev commented Sep 2, 2023

If one of the alternatives contains duplicate variables, an error will be reported in other alternatives that the variable is not bound although it is.

let _x = match or5 {
    Struct { x, y: x, .. } | Struct { x, .. } => x,
                             ^^^^^^^^^^^^^^^^ Variable "x" is not bound in all patterns
    ...
 };
@ironcev ironcev added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler: static-analysis labels Sep 2, 2023
@ironcev ironcev self-assigned this Sep 2, 2023
@ironcev ironcev added the bug Something isn't working label Sep 2, 2023
ironcev added a commit that referenced this issue Sep 22, 2023
## Description

This PR fixes three issues related to variables in match arm
alternatives:
- removes the wrong error message that a variable in match arm
alternative is not defined (#5082).
- emits error if the same variable in match arm alternatives is not of
the same type in all alternatives (#5081).
- emits all errors in a match arm instead of short-circuiting after the
first error (#5108)

Closes #5081.
Closes #5082.
Closes #5108.

## Demo


![image](https://github.com/FuelLabs/sway/assets/4142833/fea1a3c9-d58a-423e-a9df-0ca594f3162f)


![image](https://github.com/FuelLabs/sway/assets/4142833/695daba6-1825-4548-92b3-789ab519512e)

## Checklist

- [x] I have linked to any relevant issues.
- [x] 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).
- [x] 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.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: Anton Trunov <anton.a.trunov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler: static-analysis compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant