gleam-lang/gleam

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

クローズ

#5,748 opened on 2026/05/24

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)Rust (960 件のフォーク)batch import
help wanted

Repository metrics

Stars
 (21,417 個のスター)
PR merge metrics
 (平均マージ 10d 19h) (30d で 69 merged PRs)

説明

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

コントリビューターガイド