Ideas to improve OCaml's syntax errors
I've come across two ocaml/ocaml issues related to sub-optimal syntax error and thought I would add them here (before I forget). They are:
- ocaml/ocaml#5068
- ocaml/ocaml#7858
Thanks for listing these errors. I think #5068 already provides a decent error message, but #7858 is new to me.
I will look at both in January :)
More cases:
- https://github.com/ocaml/ocaml/issues/10700
- https://github.com/ocaml/ocaml/issues/11108
Here's another one (which might be harder though):
- https://github.com/ocaml/ocaml/issues/10990
Another one (for .mli files):
- https://github.com/ocaml/ocaml/issues/12055
Here's a recent one from Discuss also related to constructor arguments:
- https://discuss.ocaml.org/t/baffled-by-this-compile-error/11767
Here's another one for signatures: https://github.com/ocaml/ocaml/issues/12280
Here's a classic, caused by confusing the two let-forms: https://discuss.ocaml.org/t/syntax-error-on-in/12297
(if nothing else, it would be nice to confirm that it is handled nicely)
I came across another one, involving a trailing function semi-colon: https://github.com/ocaml/ocaml/pull/102#issuecomment-56207467
Another one - giving a nice error message on #require and friends: https://github.com/ocaml/ocaml/issues/12554
Here's a classic, caused by confusing the two
let-forms: https://discuss.ocaml.org/t/syntax-error-on-in/12297 (if nothing else, it would be nice to confirm that it is handled nicely)
Nice variation that I missed. Thanks.
I came across another one, involving a trailing function semi-colon: ocaml/ocaml#102 (comment)
This is handled.
Another one - giving a nice error message on #require and friends: ocaml/ocaml#12554
This could be handled at the syntactic level, though in Merlin (a long time ago), we went another way and made it a "semantic" fail. Top-level directives were syntactically allowed in any structure and were stored in the AST (as extension nodes), and were interpreted or rejected by a later pass. This allowed Merlin (in the findlib, pre-dune, era) to behave well with ocamlscript files and gracefully handle unexpected directives.
In the short-term, I will handle that as a syntax error, but longer term it might be worth upstreaming this Merlin feature to OCaml.
A fresh one from Gabriel: https://github.com/ocaml/ocaml/issues/12808