#6285·gleam

"Pattern match on variable" is offered on discards / could generate better code?

Author: yoshi-monsterCreated Sep 7, 2026Updated Oct 1, 2026
Labelshelp wanted

Hi!

I'm not sure how/if I should split that because it's kind of related to me.

I started out with this code:

gleam
let _ = argv.load()

My idea was to trigger the "Pattern match on variable" code action on that hole here, to let the language server fill in the right-hand-side of that assigment for me, similar how it can with the "Pattern match on value" code action within case expressions.

This almost worked, with the code action producing the following:

gleam
let _ = argv.load()
let argv.Argv(runtime:, program:, arguments:) = _

_ is a discard and not a valid variable, so I think this code action should not be offered. However, I also think that what I originally wanted to do, have it produce

gleam
let argv.Argv(runtime:, program:, arguments:) = argv.load()

would also be reasonable in this case and far more useful!

Basically I think the rule could be that if you trigger the code action within an existing pattern on a variablediscard that only has one expansion, then expand the pattern inline instead of converting it to a case expression or another let binding.

Does that sound reasonable?

~