MaybeJustJames/zephyr

Error in evaluator breaking code

natefaubion opened this issue · 3 comments

I've been testing the spork todo-mvc example, and it is failing when using zephyrs output. The app loads, but I think there is a bad transform, particularly around pattern matches.

For example, some original output:

  var update = function (model) {
      return function (v) {
          if (v instanceof None) {
              return Spork_Transition.purely(model);
          };
          if (v instanceof UpdatePending) {
              return Spork_Transition.purely({
                  pending: v.value0,
                  fresh: model.fresh,
                  todos: model.todos,
                  visibility: model.visibility
              });
          };
  ...

And the corresponding output from zephyr:

  var update = function (model) {
      return function (v) {
          if (v instanceof None) {
              return Spork_Transition.purely(model);
          };
          if (v instanceof UpdatePending) {
              return Spork_Transition.purely({
                  pending: v,
                  fresh: model.fresh,
                  todos: model.todos,
                  visibility: model.visibility
              });
          };
  ...

In particular this diff:
pending: v.value0,
pending: v,

This is giving me a dreaded [object Object] 🙀

I think this is Record updates. Minimal repro:

module Test where

data Action = Foo String | Bar Int
type State = { foo :: String, bar :: Int }

update :: State -> Action -> State
update state = case _ of
  Foo str -> state { foo = str }
  Bar n -> state { bar = n }
// Generated by purs version 0.12.0
"use strict";
var Foo = (function () {
    function Foo(value0) {
        this.value0 = value0;
    };
    Foo.create = function (value0) {
        return new Foo(value0);
    };
    return Foo;
})();
var Bar = (function () {
    function Bar(value0) {
        this.value0 = value0;
    };
    Bar.create = function (value0) {
        return new Bar(value0);
    };
    return Bar;
})();
var update = function (state) {
    return function (v) {
        if (v instanceof Foo) {
            return {
                foo: v,
                bar: state.bar
            };
        };
        if (v instanceof Bar) {
            return {
                foo: state.foo,
                bar: v
            };
        };
        throw new Error("Failed pattern match at Test line 8, column 16 - line 10, column 28: " + [ v.constructor.name ]);
    };
};
module.exports = {
    Foo: Foo,
    Bar: Bar,
    update: update
};
coot commented

I think I uploaded wrong version of the binary to github, if you build from master branch it will work.

Yes, I can confirm that master works. I was using the uploaded binary.