gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
17.93k stars 748 forks source link

Make unused variable warning more precise #3425

Open giacomocavalieri opened 3 months ago

giacomocavalieri commented 3 months ago

Right now when a punned variable is unused you always get the same hint on how to ignore it (which is prepend a _ to the var name). This is not really precise for punned variables:

let Wibble(arg:, arg1:) = todo
//               ^^^^^ Warning: unused, you can ignore it with an underscore `_arg1`

If one were to blindly apply the compiler's suggestion here they would get a compilation error:

let Wibble(arg:, _arg1) = todo
//               ^^^^^ Error: unlabelled arg after labelled one!

// Or even:
let Wibble(arg:, _arg1:) = todo
//                    ^ Error: I was not expecting this!

Which could be confusing for a newcomer. Once we improve unused detection using a call graph https://github.com/gleam-lang/gleam/issues/2634 we could be more precise and change the suggestion for variables brought into scope through punning and provide a valid suggestion like this:

let Wibble(arg:, arg1:) = todo
//               ^^^^^ Warning: unused, you can ignore it with an underscore `arg1: _`
lpil commented 3 months ago

Thank you