Skip to content

Commit

Permalink
Switch dummy_pos depending on compiler version
Browse files Browse the repository at this point in the history
In OCaml 4.08 the dummy position was changed to have a pos_lnum of 0
instead of 1. We need to match whatever the compiler is using.

Signed-off-by: Patrick Ferris <[email protected]>
  • Loading branch information
patricoferris committed Nov 28, 2024
1 parent a119730 commit 5936109
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 94 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ details.
to what the compiler's `-dparsetree` is.
(#530, @NathanReb)

- Change the default, dummy position in `Location.ml` to match the compiler's
(#540, @ncik-roberts, @patricoferris)

0.33.0 (2024-07-22)
-------------------

Expand Down
4 changes: 4 additions & 0 deletions astlib/location.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ include Ocaml_common.Location
let set_input_name name = input_name := name
let set_input_lexbuf lexbuf_opt = input_lexbuf := lexbuf_opt

let dummy_pos =
(*IF_NOT_AT_LEAST 407 { Lexing.pos_fname = ""; pos_lnum = 1; pos_bol = 0; pos_cnum = -1; } *)
(*IF_AT_LEAST 408 Lexing.dummy_pos *)

module Error = struct
[@@@warning "-37"]

Expand Down
4 changes: 4 additions & 0 deletions astlib/location.mli
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ val set_input_lexbuf : Lexing.lexbuf option -> unit
val none : t
(** An arbitrary value of type [t]; describes an empty ghost range. *)

val dummy_pos : Lexing.position
(** A location that is guaranteed to match the compiler's dummy position for
whichever compiler is being used. *)

(** {1 Automatically reporting errors for raised exceptions} *)

val register_error_of_exn : (exn -> Error.t option) -> unit
Expand Down
3 changes: 1 addition & 2 deletions src/location.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ type t = location = {
}

let in_file name =
(* This position matches the compiler's [dummy_pos]. *)
let loc = { pos_fname = name; pos_lnum = 0; pos_bol = 0; pos_cnum = -1 } in
let loc = { L.dummy_pos with pos_fname = name } in
{ loc_start = loc; loc_end = loc; loc_ghost = true }

let set_filename loc fn =
Expand Down
Loading

0 comments on commit 5936109

Please sign in to comment.