Skip to content

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

@chenglou

Description

@chenglou
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
        ]
      ];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions