Skip to content

Commit c4dcac5

Browse files
committed
add failing tests for nested variant type spreads
1 parent 597e453 commit c4dcac5

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
Syntax error!
3+
tests/parsing/grammar/pattern/variantSpreads.res:37:10-12
4+
5+
35 │ let lookupOpt = (b: option<b>) =>
6+
36 │ switch b {
7+
37 │ | Some(...a as a) => doWithA(a)
8+
38 │ | Some(Four) => Js.log("four")
9+
39 │ | Some(Five) => Js.log("five")
10+
11+
Did you forget a `)` here?
12+
13+
14+
Syntax error!
15+
tests/parsing/grammar/pattern/variantSpreads.res:37:10-12
16+
17+
35 │ let lookupOpt = (b: option<b>) =>
18+
36 │ switch b {
19+
37 │ | Some(...a as a) => doWithA(a)
20+
38 │ | Some(Four) => Js.log("four")
21+
39 │ | Some(Five) => Js.log("five")
22+
23+
Did you forget a `}` here?
24+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
type a = One | Two | Three
2+
type b = | ...a | Four | Five
3+
type c = Six | Seven
4+
type d = | ...b | ...c
5+
6+
let doWithA = (a: a) => {
7+
switch a {
8+
| One => Js.log("aaa")
9+
| Two => Js.log("twwwoooo")
10+
| Three => Js.log("threeeee")
11+
}
12+
}
13+
14+
let doWithB = (b: b) => {
15+
switch b {
16+
| One => Js.log("aaa")
17+
| _ => Js.log("twwwoooo")
18+
}
19+
}
20+
21+
let lookup = (b: b) =>
22+
switch b {
23+
| ...a as a => doWithA(a)
24+
| Four => Js.log("four")
25+
| Five => Js.log("five")
26+
}
27+
28+
let lookup2 = (d: d) =>
29+
switch d {
30+
| ...a as a => doWithA(a)
31+
| ...b as b => doWithB(b)
32+
| Six | Seven => Js.log("Got rest of d")
33+
}
34+
35+
let lookupOpt = (b: option<b>) =>
36+
switch b {
37+
| Some(...a as a) => doWithA(a)
38+
| Some(Four) => Js.log("four")
39+
| Some(Five) => Js.log("five")
40+
| None => Js.log("None")
41+
}

tests/tests/src/VariantPatternMatchingSpreads.res

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@ let lookup2 = (d: d) =>
3131
| ...b as b => doWithB(b)
3232
| Six | Seven => Js.log("Got rest of d")
3333
}
34+
35+
let lookupOpt = (b: option<b>) =>
36+
switch b {
37+
| Some(...a as a) => doWithA(a)
38+
| Some(Four) => Js.log("four")
39+
| Some(Five) => Js.log("five")
40+
| None => Js.log("None")
41+
}

0 commit comments

Comments
 (0)