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

Fix side effects in if-let expressions #5215

Merged
merged 4 commits into from
Oct 24, 2023

Conversation

ironcev
Copy link
Member

@ironcev ironcev commented Oct 22, 2023

Description

This PR fixes the critical issue in if-lets: #5173

if-lets were desugared to match expressions but used their own implementation for desugaring which wasn't storing the result of the matched value into a compiler generated variable but instead re-evaluated it on every access, causing side effects.

The new implementation generates exactly the same desugaring as the equivalent match expression would have, simply by forwarding the if-let desugaring to match desugaring.

Since the generated IR is different, the IR gen tests needed to be adapted as well.
Also, a single assert is commented out in the go_to_definition_for_matches LSP test until #5221 is solved.

Closes #5173.

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.

@ironcev ironcev added bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged P: critical Should be looked at before anything else compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Oct 22, 2023
@ironcev ironcev changed the title Use same code for creating match expressions and if-let Fix side effects in if-let expressions Oct 22, 2023
@ironcev ironcev marked this pull request as ready for review October 23, 2023 15:18
@ironcev ironcev requested review from a team October 23, 2023 15:18
@IGI-111 IGI-111 requested a review from a team October 24, 2023 09:17
@IGI-111 IGI-111 enabled auto-merge (squash) October 24, 2023 10:25
@IGI-111 IGI-111 merged commit 1cc0740 into master Oct 24, 2023
30 checks passed
@IGI-111 IGI-111 deleted the ironcev/5173-if-let-side-effects branch October 24, 2023 15:41
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 General compiler. Should eventually become more specific as the issue is triaged P: critical Should be looked at before anything else
Projects
None yet
Development

Successfully merging this pull request may close these issues.

if-let expression causes side effects
3 participants