Skip to content

Commit

Permalink
Complete complex patterns with variants and poly variants.
Browse files Browse the repository at this point in the history
And add a convoluted example of binding via variants.
  • Loading branch information
cristianoc committed Apr 28, 2021
1 parent 39fd21a commit e67ed97
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
8 changes: 3 additions & 5 deletions analysis/src/ProcessCmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,14 @@ let rec forItem ~env ~(exported : exported) item =
env.stamps.values
in
declareds := {declared with item = MValue declared.item} :: !declareds
| Tpat_tuple pats | Tpat_array pats ->
| Tpat_tuple pats | Tpat_array pats | Tpat_construct (_, _, pats) ->
pats |> List.iter (fun p -> handlePattern [] p)
| Tpat_or (p, _, _) -> handlePattern [] p
| Tpat_record (items, _) ->
items |> List.iter (fun (_, _, p) -> handlePattern [] p)
| Tpat_lazy p -> handlePattern [] p
| Tpat_any | Tpat_constant _
| Tpat_construct (_, _, _)
| Tpat_variant (_, _, _) ->
()
| Tpat_variant (_, Some p, _) -> handlePattern [] p
| Tpat_variant (_, None, _) | Tpat_any | Tpat_constant _ -> ()
in
List.iter
(fun {vb_pat; vb_attributes} -> handlePattern vb_attributes vb_pat)
Expand Down
24 changes: 13 additions & 11 deletions analysis/tests/src/Patterns.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ module A = {

let (xxx, yyy) = makeX()

type t = {name:string, age:int}
let makeT = () => {name:"", age:0}
type t = {name: string, age: int}

let makeT = () => {name: "", age: 0}

let {name, age} = makeT()

let (a | a, b) = makeX()

let [v1,v2,v3] = [1,2,3]
type rec arr = A(array<arr>)

let A([v1, _, _]) | _ as v1 = assert false

let lazy lazyy = lazy 3
}
Expand All @@ -21,14 +23,14 @@ let y = A.xxx

let z = A.yyy

let n = A.name
let n1 = A.name
// ^def

let n = A.a
// ^def
let n2 = A.a
// ^def

let n = A.v1
// ^def
let n3 = A.v1
// ^def

let n = A.lazyy
// ^def
let n4 = A.lazyy
// ^def
14 changes: 7 additions & 7 deletions analysis/tests/src/expected/Patterns.res.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Definition tests/src/Patterns.res 18:10
Definition tests/src/Patterns.res 20:10
{"uri": "Patterns.res", "range": {"start": {"line": 3, "character": 7}, "end": {"line": 3, "character": 10}}}

Definition tests/src/Patterns.res 23:11
Definition tests/src/Patterns.res 25:11
{"uri": "Patterns.res", "range": {"start": {"line": 9, "character": 7}, "end": {"line": 9, "character": 11}}}

Definition tests/src/Patterns.res 26:10
Definition tests/src/Patterns.res 28:11
{"uri": "Patterns.res", "range": {"start": {"line": 11, "character": 7}, "end": {"line": 11, "character": 8}}}

Definition tests/src/Patterns.res 29:10
{"uri": "Patterns.res", "range": {"start": {"line": 13, "character": 7}, "end": {"line": 13, "character": 9}}}
Definition tests/src/Patterns.res 31:11
{"uri": "Patterns.res", "range": {"start": {"line": 15, "character": 9}, "end": {"line": 15, "character": 11}}}

Definition tests/src/Patterns.res 32:10
{"uri": "Patterns.res", "range": {"start": {"line": 15, "character": 11}, "end": {"line": 15, "character": 16}}}
Definition tests/src/Patterns.res 34:11
{"uri": "Patterns.res", "range": {"start": {"line": 17, "character": 11}, "end": {"line": 17, "character": 16}}}

0 comments on commit e67ed97

Please sign in to comment.