You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Expressions like 3#0;; are ignored by the toplevel and the compiler #6604
Original bug ID: 6604 Reporter: rdicosmo Assigned to:@gasche Status: resolved (set by @gasche on 2017-10-04T09:07:17Z) Resolution: fixed Priority: normal Severity: minor Target version: 4.06.0 +dev/beta1/beta2/rc1 Fixed in version: 4.07.0+dev/beta2/rc1/rc2 Category: lexing and parsing Tags: junior_job
Bug description
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)
$ ocaml
OCaml version 4.01.0
3#0;;
^CInterrupted.
3#foo;;
Error: This expression has type int
It has no method foo
Or try to compile a file containing the single line
3#0;;
Additional information
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)
3#0;;
File "", line 1, characters 2-3:
Error: Syntax error
File "", line 1, characters 3-5:
Error: Syntax error
The '#0' is a way of setting the line number for error messages; it's used in tools like ocamlyacc.
$ cat lines1.ml
let x = 2 + 3#0
in x + "four"
$ ocamlc lines1.ml
File "lines1.ml", line 0, characters 8-14:
Error: This expression has type string but an expression was expected of type
int
$ cat lines2.ml
let x = 2 + 3
in x + "four"
$ ocamlc lines2.ml
File "lines2.ml", line 2, characters 8-14:
Error: This expression has type string but an expression was expected of type
int
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.
Activity
vicuna commentedon Oct 8, 2014
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
let x = 2 + 3#0
in x + "four"
$ ocamlc lines1.ml
File "lines1.ml", line 0, characters 8-14:
Error: This expression has type string but an expression was expected of type
int
$ cat lines2.ml
let x = 2 + 3
in x + "four"
$ ocamlc lines2.ml
File "lines2.ml", line 2, characters 8-14:
Error: This expression has type string but an expression was expected of type
int
vicuna commentedon Oct 8, 2014
Comment author: @damiendoligez
If possible, we should find a way to disable it in the toplevel.
Also, make it more robust by making the filename string mandatory.
Even better, only accept it at the beginning of a line (simply make the \n part of the token).
vicuna commentedon Dec 5, 2015
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.
vicuna commentedon Feb 16, 2017
Comment author: @xavierleroy
See ongoing work in #931
vicuna commentedon Oct 4, 2017
Comment author: @gasche
Fixed in trunk (will not be in 4.06) by the aforementioned PR from Tadeu Zagallo.
update the manual concerning line number directives
update the manual concerning line number directives
update the manual concerning line number directives