Skip to content

Constant folding a pattern match on an unboxed variant produces an incorrect result #6950

Open
@Innf107

Description

@Innf107

Given an unboxed variant like this, Primary has the same runtime representation as Color("primary")

@unboxed
type color =
  | @as("primary") Primary
  | @as("secondary") Secondary
  | Color(string)

This means that a function like

let f = x =>
  switch x {
  | Color(x) => x
  | _ => "not Color"
  }

somewhat surprisingly produces "not Color" when called on Color("primary").

However, the optimizer treats this like a regular variant and so constant folding f(Color("primary")) produces "primary", which differs from the result of the generated JS.

Full playground example

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions