Expressions like 3#0;; are ignored by the toplevel and the compiler #6604
Original bug ID: 6604
The very simple syntactically incorrect expression 3#0;; is simply ignored both by the toplevel and the compiler. On the other hand, 3#foo;; is handled properly
Steps to reproduce
Just type 3#0;; in any toplevel (tested 3.12 , 4.00, 4.01 and 4.02)
Error: This expression has type int
Or try to compile a file containing the single line
The interpreter executed via js_of_ocaml (see try.ocamlpro.org, for example) does not exhibit this behaviour.
Welcome to TryOCaml (v. 4.01.0)
File "", line 1, characters 2-3:
The text was updated successfully, but these errors were encountered:
Comment author: @yallop
The '#0' is a way of setting the line number for error messages; it's used in tools like ocamlyacc.
$ cat lines1.ml
Comment author: @xavierleroy
The '# lineno filename' directive is handled directly within the lexer, so it is not particularly natural to turn it off in the toplevel.
I agree with making the filename string mandatory. The filename is always there in '# lineno filename' directives generated by ocamllex, ocamlyacc, gcc -E and clang -E.
Recognizing '#' only at beginning of line would make things more robust too. However, it's not good enough to just recognize "\n#", because it doesn't work for the first line. gcc -E and clang -E will gladly generate '# lineno filename' as the first line of output.