Skip to content

"convert to use" action - error when parameters are out of order #4498

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

Open
CloserToTheCenter opened this issue Apr 23, 2025 · 3 comments · May be fixed by #4514
Open

"convert to use" action - error when parameters are out of order #4498

CloserToTheCenter opened this issue Apr 23, 2025 · 3 comments · May be fixed by #4514
Labels
help wanted Contributions encouraged priority:high

Comments

@CloserToTheCenter
Copy link

Issue with "convert to use" refactoring action.

When using parameter tags to call a function with "out-of-order" parameters, the refactoring action produces invalid code.

fn refactors_okay(items) {
  list.fold(items, from: 0, with: fn (total, item) { 
    total + item 
  })
}

fn buggy(items) {
  // now the starting point "0" comes first
  list.fold(0, over: items, with: fn (total, item) {
    total + item
  })
}

// the above is valid gleam code but refactors to this invalid code
fn buggy_refactor(items) {
  use total, item <- list.fold(0) // missing the "items" parameter
  total + item
}

I organically arrived at out of order parameters because I had

my_object.long_involved_constructor()
|> list.fold(over: items, with: fn (a, b) { todo })

// then I used the "inline pipe" action
list.fold(my_object.long_involved_constructor(), over: items, with: fn (a, b) { todo })

// then I used the "convert to use" action
use a, b <- list.fold(my_object.long_involved_constructor())
todo

// but now the "items" variable has gone missing

Gleam version 1.9.1

@CloserToTheCenter CloserToTheCenter changed the title "convert to use" action - error handling different parameter orders "convert to use" action - error when parameter are out of order Apr 23, 2025
@CloserToTheCenter CloserToTheCenter changed the title "convert to use" action - error when parameter are out of order "convert to use" action - error when parameters are out of order Apr 23, 2025
@lpil
Copy link
Member

lpil commented Apr 24, 2025

Thank you!

To make sure I understand, is the situation that you ran the code action on some invalid code?

@CloserToTheCenter
Copy link
Author

Run the code action on valid code and it outputs invalid, broken code.

@lpil
Copy link
Member

lpil commented Apr 27, 2025

AH! Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions encouraged priority:high
Projects
None yet
2 participants