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

Wrong go to definition in match expression when matched value and the scrutinee are the same #5221

Open
ironcev opened this issue Oct 23, 2023 · 0 comments
Assignees
Labels
bug Something isn't working language server LSP server

Comments

@ironcev
Copy link
Member

ironcev commented Oct 23, 2023

In the below example, when going to definition for both EXAMPLE_CONSTs in the match expression we should land on the definition of the constant. This is the case for the first EXAMPLE_CONST. However, when calling Go to Definition for the second instance, for the scrutinee, we land on the EXAMPLE_CONST above, the matched value in the match expression.

const EXAMPLE_CONST = 0;

...

match EXAMPLE_CONST {
    EXAMPLE_CONST => {}
    _ => {}
}

I've extended the go_to_definition_for_matches() test to demonstrate the issue. The extended test and fixture can be found in the branch ironcev/go-to-definition-issue-in-match-exp:

@ironcev ironcev added bug Something isn't working language server LSP server labels Oct 23, 2023
IGI-111 pushed a commit that referenced this issue Oct 24, 2023
## Description

This PR fixes the critical issue in `if-let`s: #5173

`if-let`s 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

- [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.
@JoshuaBatty JoshuaBatty self-assigned this Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working language server LSP server
Projects
None yet
Development

No branches or pull requests

2 participants