File tree 2 files changed +14
-5
lines changed
library/src/scala/reflect
2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ trait TypeTest[-S, T] extends Serializable:
20
20
* `SomeExtractor(...)` is turned into `tt(SomeExtractor(...))` if `T` in `SomeExtractor.unapply(x: T)`
21
21
* is uncheckable, but we have an instance of `TypeTest[S, T]`.
22
22
*/
23
- def unapply (x : S ): Option [x.type & T ]
23
+ def unapply (x : S ): Option [x.type & T ] @ scala.annotation.covers[ T ]
24
24
25
25
object TypeTest :
26
26
Original file line number Diff line number Diff line change @@ -34,12 +34,12 @@ object test2lib {
34
34
35
35
type ParamClause = ValDefs | TypeDefs
36
36
37
- object ValDefs with
37
+ object ValDefs :
38
38
def unapply (pc : ParamClause ): Option [ValDefs ] @ covers[ValDefs ] = ??? // matches empty list and all lists of ValDefs
39
39
40
40
def apply (vals : List [ValDef ]): ValDefs = vals
41
41
42
- object TypeDefs with
42
+ object TypeDefs :
43
43
def unapply (pc : ParamClause ): Option [TypeDefs ] @ covers[TypeDefs ] = ??? // matches non-empty lists of TypeDefs
44
44
45
45
def apply (tdefs : List [TypeDef ]): TypeDefs =
@@ -64,15 +64,15 @@ object test3lib {
64
64
65
65
type Num = Nat | Neg
66
66
67
- object Nat with
67
+ object Nat :
68
68
def unapply (x : Num ): Option [Nat ] @ covers[Nat ] =
69
69
if x >= 0 then Some (x) else None
70
70
71
71
def apply (x : Int ): Nat =
72
72
assert(x >= 0 )
73
73
x
74
74
75
- object Neg with
75
+ object Neg :
76
76
def unapply (x : Num ): Option [Neg ] @ covers[Neg ] =
77
77
if x < 0 then Some (x) else None
78
78
@@ -88,4 +88,13 @@ object test3 {
88
88
x match
89
89
case Nat (x) =>
90
90
case Neg (x) =>
91
+ }
92
+
93
+ object test4 {
94
+ import scala .reflect .TypeTest
95
+
96
+ def test [A ](a : A | String )(using TypeTest [A | String , A ]) =
97
+ a match
98
+ case a : A =>
99
+ case s : String =>
91
100
}
You can’t perform that action at this time.
0 commit comments