Skip to content

Commit

Permalink
destruct: Removal of residual patterns (#1737)
Browse files Browse the repository at this point in the history
fixes #1560

from xvw/1560-destruct-should-not-produce-remanent-cases
  • Loading branch information
voodoos committed Feb 26, 2024
2 parents 7017cc2 + af62e12 commit 3488e07
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
merlin NEXT_VERSION
==================

+ merlin binary
- destruct: Removal of residual patterns (#1737, fixes #1560)

merlin 4.14
===========
Thu Feb 22 14:00:42 CET 2024
Expand Down
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
162 changes: 162 additions & 0 deletions tests/test-dirs/destruct/issue1560.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
$ $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": []
}

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

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

0 comments on commit 3488e07

Please sign in to comment.