gleam-lang/gleam

Equality with an aliased variant silently returns False on JavaScript

已关闭

#5,757 创建于 2026年5月27日

 (2 条评论) (0 个反应) (0 位负责人)Rust (960 个派生)batch import
help wantedhigh priority

仓库指标

星标
 (21,417 个星标)
PR 合并指标
 (平均合并 10天 19小时) (30 天内合并 69 个 PR)

描述

  • Gleam: 1.16.x
  • Target: javascript only — Erlang is unaffected

On the JavaScript target, comparing a value to a no-args variant that you imported under an alias can produce the wrong result. The same code compiled to Erlang works correctly.

// src/aliased_variant_bug/foo.gleam
pub type FooStatus { Active Inactive }

// src/aliased_variant_bug/bar.gleam
pub type BarStatus { Active Disabled }

// src/aliased_variant_bug.gleam
import aliased_variant_bug/bar.{type BarStatus, Active as BarActive}
import aliased_variant_bug/foo.{type FooStatus, Active}

pub fn is_foo_active(s: FooStatus) -> Bool { s == Active }
pub fn is_bar_active(s: BarStatus) -> Bool { s == BarActive }

Generated aliased_variant_bug.mjs:

import * as $bar from "./aliased_variant_bug/bar.mjs";
import { Active as BarActive } from "./aliased_variant_bug/bar.mjs";
import * as $foo from "./aliased_variant_bug/foo.mjs";
import { Active } from "./aliased_variant_bug/foo.mjs";

export function is_foo_active(s) { return s instanceof Active; }
export function is_bar_active(s) { return s instanceof Active; }  // wrong — should be BarActive

贡献者指南