Skip to content

Commit

Permalink
Fix issue #1862
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed Oct 31, 2024
1 parent 77481f5 commit 43b48f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
10 changes: 2 additions & 8 deletions src/analysis/jump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ let is_node_let = function
| Value_binding _ -> true
| _ -> false

let is_node_pattern = function
| Case _ -> true
| _ -> false

let fun_pred all =
(* For:
`let f x y z = ...` jump to f
Expand All @@ -54,15 +50,13 @@ let fun_pred all =
For
`List.map l ~f:(fun x -> ...)` jump to fun
Every fun is immediately followed by pattern in the typed tree.
Invariant: head is a fun.
*)
let rec normalize_fun = function
(* fun pat fun something *)
| node1 :: node2 :: node3 :: tail when is_node_fun node3 ->
| node1 :: node2 :: tail when is_node_fun node2 ->
assert (is_node_fun node1);
assert (is_node_pattern node2);
normalize_fun (node3 :: tail)
normalize_fun (node2 :: tail)
(* fun let something *)
| node1 :: node2 :: _ when is_node_let node2 ->
assert (is_node_fun node1);
Expand Down
31 changes: 16 additions & 15 deletions tests/test-dirs/jump-issue1862.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@
> let f = fun x -> fun y -> fun z ->
> ()
> EOF
FIXME: Jump to `fun` should not raise an exception and jump to 1:25

Jump to `fun` should not raise an exception and jump to 1:20
$ $MERLIN single jump -target fun -position 2:4 \
> -filename main.ml <main.ml | tr '\n' ' ' | jq '.class'
"exception"
> -filename main.ml <main.ml | jq '.value.pos'
{
"line": 1,
"col": 20
}

Shoud jump to line 3
$ $MERLIN single jump -target fun -position 4:4 \
> -filename main.ml <main.ml
> -filename main.ml <main.ml | jq '.value.pos'
{
"class": "return",
"value": {
"pos": {
"line": 3,
"col": 0
}
},
"notifications": []
"line": 3,
"col": 0
}

FIXME shoud jump to line 5
Shoud jump to line 5
$ $MERLIN single jump -target fun -position 6:4 \
> -filename main.ml <main.ml | tr '\n' ' ' | jq '.class'
"exception"
> -filename main.ml <main.ml | jq '.value.pos'
{
"line": 5,
"col": 0
}

0 comments on commit 43b48f4

Please sign in to comment.