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

"Extract Variable" doesn't properly work with use and case #4269

Open
GearsDatapacks opened this issue Feb 20, 2025 · 1 comment
Open

"Extract Variable" doesn't properly work with use and case #4269

GearsDatapacks opened this issue Feb 20, 2025 · 1 comment
Labels
good first issue Good for newcomers help wanted Contributions encouraged priority:high

Comments

@GearsDatapacks
Copy link
Member

GearsDatapacks commented Feb 20, 2025

The "extract variable" code action is offered in a couple of places where it shouldn't be. Inside use callbacks:

import gleam/result

pub fn main() {
  use x <- result.try(todo)
  Ok(x + 1)
}

Which transforms into:

import gleam/result

pub fn main() {
  let value = Ok(x + 1)
  use x <- result.try(todo)
  value
}

And also inside a case body:

pub fn main(result: Result(Int, String)) {
  case result {
    Ok(value) -> value + 1
    Error(_) -> panic
  }
}

Which becomes:

pub fn main(result: Result(Int, String)) {
  let int = value + 1
  case result {
    Ok(value) -> int
    Error(_) -> panic
  }
}

In both of these cases, a variable is referenced outside of the scope which it is created in, producing invalid Gleam code.

@lpil lpil added help wanted Contributions encouraged good first issue Good for newcomers priority:high labels Feb 21, 2025
@lpil
Copy link
Member

lpil commented Feb 21, 2025

Oh dear! Thank you

@lpil lpil removed the bug label Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Contributions encouraged priority:high
Projects
None yet
Development

No branches or pull requests

2 participants