annoymous function was not handled correctly
type foo =
| Bar
| Baz;
let x = 2;
let fooToString =
fun
| Bar => string_of_int (x) + "Bar"
| Baz => "Baz";
npx bsc -format xx.re
type foo =
| Bar
| Baz
let x = 2
let fooToString = x =>
switch x {
| Bar => string_of_int(x) + "Bar"
| Baz => "Baz"
}
ping? This seems a serious bug
@bobzhang will prioritize, looking into this today
IIUC, this is a bug only in printing, in rescript syntax, all parameters should be named, is it correct?
Yes, to explain it in ast-terms, we don't have syntax for Pexp_function only for Pexp_fun. When you convert/print fun | (Pexp_function) from OCaml or Reason we transform it into a Pexp_fun with switch x { | … }.
I've looked into the naming problem, but the only "correct" way would be to re-introduce a syntax for Pexp_function.
The idea was that forcing naming of parameters would be a good thing…
But this can be re-done. I'm open to suggestions.
I hit a bug when doing the formatting, the function get broken is below:
let rec add x data = function
Empty ->
Node(Empty, x, data, Empty, 1)
| Node(l, v, d, r, h) ->
let c = compare x v in
if c = 0 then
Node(l, x, data, r, h)
else if c < 0 then
bal (add x data l) v d r
else
bal l v d (add x data r)
So the conversion is of high risky, a temporary solution is to change names from x to argument to reduce the risk.
Edit: since the parser already know one of the argument is called x, it should error out for such transformation to tell users to adapt their code
The rescript-lang/syntax repo is obsolete and will be archived soon. If this issue is still relevant, please reopen in the compiler repo (https://github.com/rescript-lang/rescript-compiler) or comment here to ask for it to be moved. Thank you for your contributions.