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.