Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object literal syntax needs a paren when printing as js #3980

Closed
chenglou opened this issue Nov 20, 2019 · 0 comments
Closed

object literal syntax needs a paren when printing as js #3980

chenglou opened this issue Nov 20, 2019 · 0 comments

Comments

@chenglou
Copy link
Member

chenglou commented Nov 20, 2019

type student = {
  name: string;
  age: int;
}
let _ =
  match (Some 1) with
  | Some 1 ->
    match [%raw "1"] with
     | 1 -> {name = "hi"; age = 1}
     | 2 -> {
         name = "bye";
         age = Js.Math.floor 1.
       }

In the new compiler version, this generates a JS syntax error.

var match = 1;

if (match !== undefined) {
  if (match !== 1) {
    throw [
          Caml_builtin_exceptions.match_failure,
          /* tuple */[
            "Index.ml",
            387,
            0
          ]
        ];
  }
  var match$1 = (1);
  if (match$1 !== 1) {
    if (match$1 !== 2) {
      throw [
            Caml_builtin_exceptions.match_failure,
            /* tuple */[
              "Index.ml",
              389,
              2
            ]
          ];
    }
    // here!
    {
      name: "bye",
      age: Js_math.floor(1)
    };
  }
  
} else {
  throw [
        Caml_builtin_exceptions.match_failure,
        /* tuple */[
          "Index.ml",
          387,
          0
        ]
      ];
}
@bobzhang bobzhang changed the title Pattern matching incorrectly compiled object literal syntax needs a paren when printing as js Nov 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant