Skip to content

Commit 65ba3f8

Browse files
authored
Merge pull request #1944 from voodoos/fix-destruct-pprintast-hang
Fix destruct pprintast hang
2 parents 4489ad7 + 44ff26a commit 65ba3f8

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ unreleased
1717
to scopes bit masks when backtracking the typer cache (#1935)
1818
- Add a new selection field to outline results that contains the location of
1919
the symbol itself. (#1942)
20+
- Fix destruct hanging when printing patterns with (::). (#1944, fixes
21+
ocaml/ocaml-lsp#1489)
2022
+ ocaml-index
2123
- Improve the granularity of index reading by segmenting the marshalization
2224
of the involved data-structures. (#1889)

src/ocaml/parsing/pprintast.ml

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -548,37 +548,28 @@ and pattern_or ctxt f x =
548548
pp f "@[<hov0>%a@]" (list ~sep:"@ | " (pattern1 ctxt)) orpats
549549

550550
and pattern1 ctxt (f:Format.formatter) (x:pattern) : unit =
551-
let rec pattern_list_helper f = function
552-
| {ppat_desc =
553-
Ppat_construct
554-
({ txt = Lident("::") ;_},
555-
Some ([], {ppat_desc = Ppat_tuple([pat1; pat2]);_}));
556-
ppat_attributes = []}
557-
558-
->
559-
pp f "%a::%a" (simple_pattern ctxt) pat1 pattern_list_helper pat2 (*RA*)
560-
| p -> pattern1 ctxt f p
561-
in
562551
if x.ppat_attributes <> [] then pattern ctxt f x
563552
else match x.ppat_desc with
564553
| Ppat_variant (l, Some p) ->
565554
pp f "@[<2>`%a@;%a@]" ident_of_name l (simple_pattern ctxt) p
566555
| Ppat_construct (({txt=Lident("()"|"[]"|"true"|"false");_}), _) ->
567556
simple_pattern ctxt f x
568-
| Ppat_construct (({txt;_} as li), po) ->
557+
| Ppat_construct (
558+
{txt=Lident("::");_},
559+
Some ([], {ppat_desc = Ppat_tuple([pat1; pat2]);_}))
560+
when x.ppat_attributes = [] ->
561+
pp f "%a::%a" (simple_pattern ctxt) pat1 (pattern1 ctxt) pat2 (*RA*)
562+
| Ppat_construct (li, po) ->
569563
(* FIXME The third field always false *)
570-
if txt = Lident "::" then
571-
pp f "%a" pattern_list_helper x
572-
else
573-
(match po with
574-
| Some ([], x) ->
575-
(* [true] and [false] are handled above *)
576-
pp f "%a@;%a" value_longident_loc li (simple_pattern ctxt) x
577-
| Some (vl, x) ->
578-
pp f "%a@ (type %a)@;%a" value_longident_loc li
579-
(list ~sep:"@ " ident_of_name_loc) vl
580-
(simple_pattern ctxt) x
581-
| None -> pp f "%a" value_longident_loc li)
564+
(match po with
565+
| Some ([], x) ->
566+
(* [true] and [false] are handled above *)
567+
pp f "%a@;%a" value_longident_loc li (simple_pattern ctxt) x
568+
| Some (vl, x) ->
569+
pp f "%a@ (type %a)@;%a" value_longident_loc li
570+
(list ~sep:"@ " ident_of_name_loc) vl
571+
(simple_pattern ctxt) x
572+
| None -> pp f "%a" value_longident_loc li)
582573
| _ -> simple_pattern ctxt f x
583574

584575
and simple_pattern ctxt (f:Format.formatter) (x:pattern) : unit =

tests/test-dirs/lsp-issue1489.t

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
$ cat >repro.ml <<'EOF'
2+
> type t = ( :: )
3+
> let f (x: t) = x
4+
> EOF
5+
6+
This should not hang and return a matching.
7+
$ $MERLIN single case-analysis -start 2:16 -end 2:17 \
8+
> -filename repro.ml <repro.ml
9+
{
10+
"class": "return",
11+
"value": [
12+
{
13+
"start": {
14+
"line": 2,
15+
"col": 16
16+
},
17+
"end": {
18+
"line": 2,
19+
"col": 17
20+
}
21+
},
22+
"match x with | (::) -> _"
23+
],
24+
"notifications": []
25+
}

0 commit comments

Comments
 (0)