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 bug with extract variable top level statements #4100

Merged
merged 2 commits into from
Dec 22, 2024

Conversation

giacomocavalieri
Copy link
Member

Experimenting with the nightly compiler I noticed a couple of bugs with the "extract variable" code action I've recently added:

  • It would allow extracting top level expressions, not all that useful:
    pub fn main() {
      1
    //^ [Extract variable]
    }
    
    // turned into:
    
    pub fn main() {
      let value = 1
      value
    }
  • It would extract module selects on their own instead of considering those as part of an outer function call, resulting in an error:
    pub fn main() {
      list.map(list.filter([1, 2, 3], todo), todo)
    //          ^ [Extract variable]
    }
    
    // turned into:
    
    pub fn main() {
      let value = list.
      list.map(valuefilter([1, 2, 3], todo), todo)
    }

This PR fixes both

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Thank you!!!

@lpil lpil merged commit 190239b into gleam-lang:main Dec 22, 2024
12 checks passed
@giacomocavalieri giacomocavalieri deleted the fix-extract-variable branch December 22, 2024 10:55
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

Successfully merging this pull request may close these issues.

2 participants