diff --git a/src/lib/uTop.ml b/src/lib/uTop.ml index dfbcd1a..8904826 100644 --- a/src/lib/uTop.ml +++ b/src/lib/uTop.ml @@ -307,16 +307,22 @@ let check_phrase phrase = } in let check_phrase = Parsetree.Ptop_def [top_def] in try - let _ = discard_formatters [Format.err_formatter] (fun () -> Toploop.execute_phrase false null check_phrase) in + let _ = + discard_formatters [Format.err_formatter] (fun () -> +#if ocaml_version > (4, 00, 1) + Env.reset_cache_toplevel (); +#endif + Toploop.execute_phrase false null check_phrase) + in (* The phrase is safe. *) Toploop.toplevel_env := env; Btype.backtrack snap; None with exn -> (* The phrase contains errors. *) + let loc, msg = get_ocaml_error_message exn in Toploop.toplevel_env := env; Btype.backtrack snap; - let loc, msg = get_ocaml_error_message exn in Some ([loc], msg) (* +-----------------------------------------------------------------+ diff --git a/src/lib/uTop_main.ml b/src/lib/uTop_main.ml index 6f125cd..7285ec3 100644 --- a/src/lib/uTop_main.ml +++ b/src/lib/uTop_main.ml @@ -538,6 +538,9 @@ let rec loop term = let pp = Format.formatter_of_buffer buffer in Format.pp_set_margin pp (LTerm.size term).cols; (try +#if ocaml_version > (4, 00, 1) + Env.reset_cache_toplevel (); +#endif ignore (Toploop.execute_phrase true pp phrase); (* Flush everything. *) Format.pp_print_flush Format.std_formatter (); @@ -742,6 +745,7 @@ module Emacs(M : sig end) = struct (* Rewrite toplevel expressions. *) let phrase = rewrite phrase in try + Env.reset_cache_toplevel (); ignore (Toploop.execute_phrase true Format.std_formatter phrase); true with exn ->