Skip to content

A bool payload beside a bool literal never matches in an incomplete match #9035

Closed

Description

@cknitt

In an untagged variant with a bool literal and a bool payload, a match that doesn't name every case sends values to the wrong arm:

@unboxed type t = | @as(true) LitTrue | AnyBool(bool) | AnyInt(int)
let f = (v: t) =>
  switch v {
  | AnyBool(_) => "bool"
  | _ => "other"
  }
Console.log([LitTrue, AnyBool(false), AnyInt(1)]->Array.map(f))
function f(v) {
  return "other";
}

f(AnyBool(false)) returns "other", but should return "bool". With @as(false) instead of @as(true), every value goes to the AnyBool arm.

Observed on master (d48d577). Cause: Js_exp_make.simplify_and_ rewrites typeof x === "boolean" && x !== b to the constant !b. Its doc comment says the result is x === !b, which is what's correct. The match produces exactly this conjunction for a bool payload beside a bool literal.

Found by a review of the untagged variant work (#8950).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions