Skip to content

Commit

Permalink
fix: set input_lexbuf when reading binary AST too
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Nuno Monteiro <[email protected]>
  • Loading branch information
anmonteiro authored and NathanReb committed Apr 18, 2024
1 parent c53a314 commit e3a72e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ module Ast_io = struct
let s = Bytes.sub_string buf ~pos:0 ~len in
if len = magic_length then Ok s else Error s

let set_input_lexbuf input_name =
let set_input_lexbuf ic =
(* set input lexbuf for error messages. *)
let source = In_channel.input_all ic in
let lexbuf = Lexing.from_string source in
Astlib.Location.set_input_lexbuf (Some lexbuf);
lexbuf
in
match In_channel.with_file ~binary:true input_name ~f:set_input_lexbuf with
| (_ : Lexing.lexbuf) -> ()
| exception Sys_error _ -> ()

let from_channel ch ~input_kind =
let handle_non_binary prefix_read_from_source =
match input_kind with
Expand All @@ -133,6 +145,7 @@ module Ast_io = struct
let input_name : string = input_value ch in
let ast = input_value ch in
let module Input_to_ppxlib = Convert (Input_version) (Js) in
set_input_lexbuf input_name;
let ast = Intf_or_impl.Intf (Input_to_ppxlib.copy_signature ast) in
Ok
{
Expand All @@ -144,6 +157,7 @@ module Ast_io = struct
let input_name : string = input_value ch in
let ast = input_value ch in
let module Input_to_ppxlib = Convert (Input_version) (Js) in
set_input_lexbuf input_name;
let ast = Intf_or_impl.Impl (Input_to_ppxlib.copy_structure ast) in
Ok
{
Expand Down
2 changes: 2 additions & 0 deletions test/driver/source-quotation-in-errors/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ error with source quotation:

$ ./raising_driver.exe -impl file.pp.ml
File "file.ml", line 1, characters 8-16:
1 | let x = [%raise]
^^^^^^^^
Error: An exception, raise be!
[1]

0 comments on commit e3a72e7

Please sign in to comment.