purescript-contrib / purescript-formatters

Formatting and printing for numeric and date/time/interval values
Apache License 2.0
41 stars 30 forks source link

`unformat` gives a runtime error with purescript-backend-optimizer #84

Closed dariooddenino closed 2 years ago

dariooddenino commented 2 years ago

Using unformat results in a runtime error

main = do
  let res = unformat (fromFoldable [YearFull]) "2022"
  logShow res

spago build && purs-backend-es bundle-app --no-build --to out.js

This results in this runtime error:

Uncaught TypeError: lift1(...) is not a function ...
...
  var unformatCommandParser = (v) => {
    if (v.tag === "YearFull") {
      return (state1, more, lift1, $$throw, done) => more((v1) => parseSignedInt(monadStateT2)(4)(exactLength)("Incorrect full year")(state1, more, lift1, $$throw, (state2, a) => more((v2) => lift1(monadStateStateT2.state((s) => $Tuple(unit, { year: $Maybe("Just", a), day: s.day, hour: s.hour, meridiem: s.meridiem, millisecond: s.millisecond, minute: s.minute, month: s.month, second: s.second })))(state2, more, lift1, $$throw, done))));
    }
...

I've tried creating various mimimal cases involving mapParserT, State, etc. but I was never able to reproduce this issue, sorry!

garyb commented 2 years ago

Thanks for trying to figure it out! :+1:

I can't look into this immediately, but will definitely do so when I can.

garyb commented 2 years ago

I've pretty much figured it out, it is a bug in purescript-backend-optimizer rather than something dodgy this library is doing. Will close this and open an issue there once I've got it down to a minimal reproduction, as it's quite tangled!

garyb commented 2 years ago

https://github.com/aristanetworks/purescript-backend-optimizer/issues/26

garyb commented 2 years ago

This was fixed in https://github.com/aristanetworks/purescript-backend-optimizer/pull/27, and was released as v1.1.1 🎉