Skip to content

Commit

Permalink
destruct: Removal of residual patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
xvw committed Feb 23, 2024
1 parent 7017cc2 commit 99ebdb8
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/analysis/destruct.ml
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,7 @@ let rec node config source selected_node parents =
subst_patt patt ~by top_patt
)
in
let patterns =
List.rev_append rev_before
(List.append new_branches after)
in
let patterns = after @ rev_before @ new_branches in
let unused = Parmatch.return_unused patterns in
let new_branches =
List.fold_left unused ~init:new_branches ~f:(fun branches u ->
Expand Down
116 changes: 116 additions & 0 deletions tests/test-dirs/destruct/issue1560.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
$ $MERLIN single case-analysis -start 2:29 -end 2:29 \
> -filename main.ml <<EOF
> type t = A of int | B | C
> let f = function A x -> x | _ -> 1
> EOF
{
"class": "return",
"value": [
{
"start": {
"line": 2,
"col": 28
},
"end": {
"line": 2,
"col": 29
}
},
"B | C"
],
"notifications": []
}

$ $MERLIN single case-analysis -start 2:18 -end 2:18 \
> -filename main.ml <<EOF
> type t = A of int | B | C
> let f = function A x -> x
> EOF
{
"class": "return",
"value": [
{
"start": {
"line": 2,
"col": 25
},
"end": {
"line": 2,
"col": 25
}
},
"
| B | C -> _"
],
"notifications": []
}


$ $MERLIN single case-analysis -start 2:29 -end 2:29 \
> -filename main.ml <<EOF
> type t = A of int | B | C
> let f = function A 0 -> 0 | _ -> 1
> EOF
{
"class": "return",
"value": [
{
"start": {
"line": 2,
"col": 28
},
"end": {
"line": 2,
"col": 29
}
},
"A _ | B | C"
],
"notifications": []
}

$ $MERLIN single case-analysis -start 2:29 -end 2:29 \
> -filename main.ml <<EOF
> type t = A of int | B | C
> let f = function A x -> x | _ -> 1 | C -> 2
> EOF
{
"class": "return",
"value": [
{
"start": {
"line": 2,
"col": 28
},
"end": {
"line": 2,
"col": 29
}
},
"B"
],
"notifications": []
}

$ $MERLIN single case-analysis -start 2:38 -end 2:38 \
> -filename main.ml <<EOF
> type t = A of int | B | C
> let f = function A x -> x | C -> 2 | _ -> 1
> EOF
{
"class": "return",
"value": [
{
"start": {
"line": 2,
"col": 37
},
"end": {
"line": 2,
"col": 38
}
},
"B"
],
"notifications": []
}

0 comments on commit 99ebdb8

Please sign in to comment.