gleam-lang/gleam

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

Fermée

#5 748 ouverte le 24 mai 2026

 (1 commentaire) (0 réaction) (0 personne assignée)Rust (960 forks)batch import
help wanted

Métriques du dépôt

Stars
 (21 417 étoiles)
Métriques de merge PR
 (Merge moyen 10j 19h) (69 PRs mergées en 30 j)

Description

  • 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.

Guide contributeur