gleam-lang/gleam

Duplicate let when a variable is rebound after a directly matching case

Chiusa

#5748 aperta il 24 mag 2026

 (1 commento) (0 reazioni) (0 assegnatari)Rust (960 fork)batch import
help wanted

Metriche repository

Star
 (21.417 stelle)
Metriche merge PR
 (Merge medio 10g 19h) (69 PR mergiate in 30 g)

Descrizione

  • gleam 1.17.0-rc1
  • target javascript

A variable shadowed inside a directly matching case branch and then rebound after the case compiles to two let declarations with the same name, which is a SyntaxError.

pub fn go() -> Int {
  let n = 1
  case True {
    True -> {
      let n = 99
      n
    }
    False -> 0
  }
  let n = n + 5
  n
}

Compiles to:

export function go() {
  let n = 1;
  let $ = true;
  let n$1 = 99;
  n$1
  let n$1 = n + 5;
  return n$1;
}

SyntaxError: Identifier 'n$1' has already been declared.

This is the same duplicate let family as #3379 and #5612, which were fixed for pattern bound variables. It still happens when the inner binding is a plain let inside the branch block. I have a fix that tracks the names already declared in a function so a leaked branch declaration isn't reused, which also lets the #5493 same-name workaround go. Happy to open a PR if that approach sounds right.

Guida contributor