Skip to content

Commit 25bf8c6

Browse files
authored
Fix let bindings formatting with dummy locations (#2654)
* Fix let bindings formatting with dummy locations Let bindings with dummy locations formatted like this: let* a = let* b = c in d in This happens when constructing new AST nodes and formatting them with ocamlformat-lib. * fmt
1 parent c8fb442 commit 25bf8c6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/Source.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ open Extended_ast
1515
(** Concrete syntax. *)
1616
type t = {text: string; tokens: (Parser.token * Location.t) array}
1717

18+
let is_dummy_pos p = p.Lexing.pos_cnum < 0
19+
1820
let create ~text ~tokens =
1921
let tokens =
2022
List.filter tokens ~f:(fun (tok, _) ->
@@ -66,7 +68,7 @@ let empty_line_between (t : t) p1 p2 =
6668
| (_tok, x) :: xs ->
6769
x.loc_start.pos_lnum - prev.pos_lnum > 1 || loop x.loc_end xs
6870
in
69-
loop p1 l
71+
(not (is_dummy_pos p1 || is_dummy_pos p2)) && loop p1 l
7072

7173
let tokens_at t ~filter (l : Location.t) : (Parser.token * Location.t) list =
7274
tokens_between t ~filter l.loc_start l.loc_end

0 commit comments

Comments
 (0)