I recently upgraded from 4.14.0 to 5.3.0 and am now looking for toplevel backtraces (which were buggy in 4.14 iirc). Running utop
with OCAMLRUNPARAM=b
does give backtraces, but they are rather frustrating.
For example, if I successively do
let rec f (h::t) = h + f t;;
let g l = f (5::l);;
g [6];;
I get
Exception: Match_failure ("//toplevel//", 1, 10).
Called from unknown location
Called from unknown location
Called from unknown location
Called from Topeval.load_lambda in file "toplevel/byte/topeval.ml", line 93, characters 4-14
which is not really useful in a non-toy situation.
As explained by @vlaviron below, the backtraces produced by the plain OCaml REPL do contain accurate information.
Has anyone got utop to produce informative backtraces ?
This is what I get using the regular toplevel:
$ OCAMLRUNPARAM=b opam exec --switch=5.3.0 -- rlwrap ocaml -noinit
OCaml version 5.3.0
Enter #help;; for help.
# let rec f (h::t) = h + f t;;
Warning 8 [partial-match]: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
[]
val f : int list -> int = <fun>
# let g l = f (5::l);;
val g : int list -> int = <fun>
# g [6];;
Exception: Match_failure ("//toplevel//", 1, 10).
Raised at f in file "//toplevel//", line 1, characters 10-16
Called from f in file "//toplevel//", line 1, characters 23-26
Called from f in file "//toplevel//", line 1, characters 23-26
Called from <unknown> in file "//toplevel//", line 1, characters 0-5
Called from Topeval.load_lambda in file "toplevel/byte/topeval.ml", line 93, characters 4-14
So I suspect that utop
is somehow not setting the debug flags correctly (or maybe it needs the same fix as the PR you linked to).
Thank you for this important spur !