Skip to content

Commit c93e2c1

Browse files
committed
Add test
1 parent d6badcf commit c93e2c1

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

tests/patmat/i10961.scala

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
object test0 {
2+
object :+ {
3+
def unapply[T](l: ::[T]): (List[T], T) = (l.tail, l.head)
4+
}
5+
6+
def f(xs: List[Int]) =
7+
xs match
8+
case init :+ last => ()
9+
case Nil => ()
10+
}
11+
12+
object test1 {
13+
import scala.annotation.covers
14+
15+
type /[T, U] = T @covers[U]
16+
17+
object :+ {
18+
def unapply[T](l: List[T]): Option[(List[T], T)] / ::[T] = ???
19+
}
20+
21+
def f(xs: List[Int]) =
22+
xs match
23+
case init :+ last => ()
24+
case Nil => ()
25+
}
26+
27+
object test2lib {
28+
import scala.annotation.covers
29+
30+
class ValDef
31+
class TypeDef
32+
opaque type ValDefs <: List[ValDef] = List[ValDef]
33+
opaque type TypeDefs <: List[TypeDef] = List[TypeDef]
34+
35+
type ParamClause = ValDefs | TypeDefs
36+
37+
object ValDefs with
38+
def unapply(pc: ParamClause): Option[ValDefs] @covers[ValDefs] = ??? // matches empty list and all lists of ValDefs
39+
40+
def apply(vals: List[ValDef]): ValDefs = vals
41+
42+
object TypeDefs with
43+
def unapply(pc: ParamClause): Option[TypeDefs] @covers[TypeDefs] = ??? // matches non-empty lists of TypeDefs
44+
45+
def apply(tdefs: List[TypeDef]): TypeDefs =
46+
assert(tdefs.nonEmpty)
47+
tdefs
48+
}
49+
50+
object test2 {
51+
import test2lib._
52+
53+
def f(pc: ParamClause) =
54+
pc match
55+
case ValDefs(vs) => ()
56+
case TypeDefs(ts) => ()
57+
}
58+
59+
object test3lib {
60+
import scala.annotation.covers
61+
62+
opaque type Nat <: Int = Int
63+
opaque type Neg <: Int = Int
64+
65+
type Num = Nat | Neg
66+
67+
object Nat with
68+
def unapply(x: Num): Option[Nat] @covers[Nat] =
69+
if x >= 0 then Some(x) else None
70+
71+
def apply(x: Int): Nat =
72+
assert(x >= 0)
73+
x
74+
75+
object Neg with
76+
def unapply(x: Num): Option[Neg] @covers[Neg] =
77+
if x < 0 then Some(x) else None
78+
79+
def apply(x: Int): Nat =
80+
assert(x < 0)
81+
x
82+
}
83+
84+
object test3 {
85+
import test3lib._
86+
87+
def foo(x: Num) =
88+
x match
89+
case Nat(x) =>
90+
case Neg(x) =>
91+
}

0 commit comments

Comments
 (0)