Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#6181·gleam

Matching on `<<_:utf8>>` takes wrong branch on JavaScript target

Author: daniellionel01Created Aug 15, 2026Updated Sep 17, 2026
Labelshelp wantedhigh priority

Given this code:

pub fn main() {
  echo case <<"a":utf8>> {
    <<_:utf8>> -> 1
    _ -> -1
  }
}

It yields different results on Erlang vs JavaScript:

/app $ gleam run -terl
src/app.gleam:2
1

/app $ gleam run -tjs
src/app.gleam:2
-1

Looking at the generated JavaScript:

export function main() {
  let _block;
  let $ = toBitArray([stringBits("a")]);
  if ($.bitSize === 64) {
    _block = 1;
  } else {
    _block = -1;
  }
  return echo(_block, undefined, "src/app.gleam", 2);
}

The bitSize of "a" is actually 8 and not 64. So for a wildcard it seems that there needs to be a better way to match :utf8 on JavaScript.

Gleam v1.18.1

Source: gleam-lang/gleam

View original on GitHubView discussion on GitHub