reasonml / reason

Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems
http://reasonml.github.io
MIT License
10.14k stars 428 forks source link

Formatting destructured record with letops results in a syntax error #2746

Closed mlms13 closed 3 months ago

mlms13 commented 3 months ago

Using the new-ish letops syntax, I'm trying to destructure a record type, assign a name to it, and provide a type annotation, all at the same time. I think doing so requires parentheses, like this (which is valid syntax that compiles correctly):

let* ({foo, bar}: Foo.t) as foobar = ...;

However, when the code is formatted, it reprints it as:

let* {foo, bar}: Foo.t as foobar = ...;

By removing the parentheses, the code no longer compiles and instead produces a syntax error.

Complete example:

module Foo = {
  type t = {
    foo: string,
    bar: int,
  };

  let makeOpt = num => Some({foo: "a", bar: num});
};

let myFn = () => {
  let ( let* ) = Belt.Option.flatMap;

  let* a = Some(3);
  let* ({foo, bar}: Foo.t) as foobar = Foo.makeOpt(a);

  Some((foo, bar, foobar, a));
};

Melange playground link