Broken pattern-match compilation with `esbuild`?

I have definitions:

newtype SelState a = SelState
   { persistent :: a
   , transient :: a

data π•Š = None | Primary | Secondary

If I define a function by (perhaps unidiomatic) pattern-matching as follows:

selClass :: SelState π•Š -> String
selClass (SelState { persistent: Primary }) = css.sel.selected
selClass (SelState { transient: Primary }) = spy "selClass: " identity css.sel.selected_transient
selClass (SelState { persistent: Secondary }) = css.sel.selected_secondary
selClass (SelState { transient: Secondary }) = css.sel.selected_secondary_transient
selClass _ = ""

then the esbuild backend (v. 0.15.1) generates the following JavaScript:

  var selClass = (v) => {
    if (v.persistent.tag === "Primary") {
      return css.sel.selected;
    if (v.persistent.tag === "Secondary") {
      return css.sel.selected_secondary;
    return "";

which doesn’t deal with the transient case. Is this a bug, and if so is it in the back end or front end? (So I know where to file a bug report if necessary.)


I’d start debugging it by:

  1. Isolating a module with the misbehaving pattern match.
  2. Looking at corefn.json in the output folder (you might have to provide a compiler flag --codegen corefn)

If by esbuild backend, you mean purs-backend-es, then it’s likely an issue with purs-backend-es. You mention using 0.15.1, which I assume is the main compiler, but this version is not supported by purs-backend-es. Can you clarify which versions of both you are using? Your issue sounds suspiciously like Case expressions with partial record binders incomplete Β· Issue #42 Β· aristanetworks/purescript-backend-optimizer Β· GitHub which has been fixed for some time.

Thanks Nate. Yes, same bug – I’ll update my versions. Sorry for mangling the package name.