Proposal: parse empty {} as unit

Currently an expression with empty braces results in a syntax error. If you write the same code in Js, it parses. It is quite common while writing code that you write out the “empty braces” first. Not sure if fixing a syntax error is good UX. Should we just parse this as a unit expression? An empty record does not exist, so there’s no conflict here.

let f = () => {}
// parses as
let f = () => {
  ()
}

for _ in 0 to 10 {
}
// parses as
for _ in 0 to 10 {
  ()
}

this is one of the more annoying errors indeed, because it’s unintuitive to add a () in an empty closure.

Even knowing it, it hits me several times during my coding sessions and it’s annoying to readjust the code, especially when I am temporarily deleting some code to try something out.

So from a UX perspective, I’d welcome the change, but I am not sure how intrusive it is from a compiler perspective.

Is that always a syntax error? If it is, then it seems a low-risk change from a language perspective: changing a syntax error into a default.
The default () seems the right semantics for {}, can’t think of another one.

Is that always a syntax error?

Yes, it is.

lgtm if there is no backward compatibility issue

So ocaml got the empty record feature; it’d clash with this. What’s our stance on it?

Actually, seems like it got rejected: https://github.com/ocaml/ocaml/issues/7583
Empty variant got accepted…?

Do you find some use cases for empty variant/record?
That would be something I tend to avoid

Never did; but I was a little more cautious seeing that we’d have a syntactic clash.

I guess never mind; let’s ship this