gleam-lang/gleam

Pattern matching on tuples or custom types produces broken JavaScript

Geschlossen

#5.680 geöffnet am 03.05.2026

 (5 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Rust (960 Forks)batch import
help wantedhigh priority

Repository-Metriken

Stars
 (21.417 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 10T 19h) (69 gemergte PRs in 30 T)

Beschreibung

The following Gleam code

pub fn main() {
  case #(1, 2) {
    #(a, _) -> a
  }
  {2 + 4} * 2
  let a = 42
  Nil
}

produces this Javascript:

export function main() {
  let $ = [1, 2];
  let a = $[0];
  a
  (2 + 4) * 2;
  let a = 42;
  return undefined;
}

Here, 2 things go wrong:

  1. the a binding does not reserve the name in the enclosing scope, causing a parse error.
  2. The expression inside the arm of the pattern is not followed by a semicolon. The line after it is constructed in such a way that this is now parsed as a function call, changing the meaning of this program.

Both of these can be triggered independently.

~ 💜

Contributor Guide