Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 2ca03d0

Browse files
Prevent printer from throwing when printing longident (#449)
* Prevent printer from throwing when printing longident * Update printLident * Rebasing on master. * No need to raise exceptions. Co-authored-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
1 parent 7a8dc63 commit 2ca03d0

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/res_printer.ml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,16 +468,29 @@ let printPolyVarIdent txt =
468468
| _ -> Doc.text txt
469469

470470

471-
let printLident l = match l with
471+
let printLident l =
472+
let flatLidOpt lid =
473+
let rec flat accu = function
474+
| Longident.Lident s -> Some (s :: accu)
475+
| Ldot (lid, s) -> flat (s :: accu) lid
476+
| Lapply (_, _) -> None
477+
in
478+
flat [] lid
479+
in
480+
match l with
472481
| Longident.Lident txt -> printIdentLike txt
473482
| Longident.Ldot (path, txt) ->
474-
let txts = Longident.flatten path in
475-
Doc.concat [
476-
Doc.join ~sep:Doc.dot (List.map Doc.text txts);
477-
Doc.dot;
478-
printIdentLike txt;
479-
]
480-
| _ -> Doc.text("printLident: Longident.Lapply is not supported")
483+
let doc = match flatLidOpt path with
484+
| Some txts ->
485+
Doc.concat [
486+
Doc.join ~sep:Doc.dot (List.map Doc.text txts);
487+
Doc.dot;
488+
printIdentLike txt;
489+
]
490+
| None -> Doc.text("printLident: Longident.Lapply is not supported")
491+
in
492+
doc
493+
| Lapply (_, _) -> Doc.text("printLident: Longident.Lapply is not supported")
481494

482495
let printLongidentLocation l cmtTbl =
483496
let doc = printLongident l.Location.txt in

0 commit comments

Comments
 (0)