lrgrep icon indicating copy to clipboard operation
lrgrep copied to clipboard

Ideas to improve OCaml's syntax errors

Open jmid opened this issue 3 years ago • 11 comments

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

jmid avatar Dec 12 '22 12:12 jmid

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 :)

let-def avatar Dec 20 '22 23:12 let-def

More cases:

  • https://github.com/ocaml/ocaml/issues/10700
  • https://github.com/ocaml/ocaml/issues/11108

let-def avatar Jan 24 '23 08:01 let-def

Here's another one (which might be harder though):

  • https://github.com/ocaml/ocaml/issues/10990

jmid avatar Feb 06 '23 08:02 jmid

Another one (for .mli files):

  • https://github.com/ocaml/ocaml/issues/12055

jmid avatar Mar 01 '23 11:03 jmid

Here's a recent one from Discuss also related to constructor arguments:

  • https://discuss.ocaml.org/t/baffled-by-this-compile-error/11767

jmid avatar Mar 23 '23 22:03 jmid

Here's another one for signatures: https://github.com/ocaml/ocaml/issues/12280

jmid avatar May 31 '23 19:05 jmid

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)

jmid avatar Jun 02 '23 07:06 jmid

I came across another one, involving a trailing function semi-colon: https://github.com/ocaml/ocaml/pull/102#issuecomment-56207467

jmid avatar Jul 12 '23 14:07 jmid

Another one - giving a nice error message on #require and friends: https://github.com/ocaml/ocaml/issues/12554

jmid avatar Sep 13 '23 19:09 jmid

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.

let-def avatar Sep 14 '23 07:09 let-def

A fresh one from Gabriel: https://github.com/ocaml/ocaml/issues/12808

jmid avatar Dec 06 '23 17:12 jmid