File tree 3 files changed +48
-0
lines changed
compiler/src/dotty/tools/dotc/transform 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,7 @@ object TypeTestsCasts {
135
135
def recur (X : Type , P : Type ): String = trace(s " recur( ${X .show}, ${P .show}) " ) {
136
136
(X <:< P ) ||| P .dealias.match
137
137
case _ : SingletonType => " "
138
+ case tp if tp.isMatchAlias => recur(X , tp.tryNormalize)
138
139
case _ : TypeProxy
139
140
if isAbstract(P ) => i " it refers to an abstract type member or type parameter "
140
141
case defn.ArrayOf (tpT) =>
Original file line number Diff line number Diff line change
1
+ import scala .reflect .TypeTest
2
+
3
+ type Matcher [A ] = A match { case String => A }
4
+
5
+ def patternMatch [A ](a : Any )(using tt : TypeTest [Any , Matcher [A ]]): Option [Matcher [A ]] = {
6
+ // type T = RDF.Triple[Rdf]
7
+ a match {
8
+ case res : Matcher [A ] => Some (res)
9
+ case _ => None
10
+ }
11
+ }
12
+
13
+ def patternMatchWithAlias [A ](a : Any )(using tt : TypeTest [Any , Matcher [A ]]): Option [Matcher [A ]] = {
14
+ type T = Matcher [A ]
15
+ a match {
16
+ case res : T => Some (res)
17
+ case _ => None
18
+ }
19
+ }
20
+
21
+ type S = String
22
+ type MS = Matcher [S ]
23
+
24
+ type S2 = MS
25
+ type MS2 = Matcher [S2 ]
Original file line number Diff line number Diff line change
1
+ //> using options -Xfatal-warnings -deprecation -feature
2
+
3
+ @ main def main = {
4
+ println(patternMatch[String ](" abc" ))
5
+ println(patternMatchWithAlias[String ](" abc" ))
6
+ println(patternMatch[String ](" abc" )(using (s : Any ) => {
7
+ if s.isInstanceOf [Matcher [String ]] then Some [s.type & Matcher [String ]](s.asInstanceOf [s.type & Matcher [String ]]) else None }))
8
+ println(patternMatchWithAlias[String ](" abc" )(using (s : Any ) => {
9
+ if s.isInstanceOf [Matcher [String ]] then Some [s.type & Matcher [String ]](s.asInstanceOf [s.type & Matcher [String ]]) else None }))
10
+
11
+ println(patternMatch[String ](1 ))
12
+ println(patternMatchWithAlias[String ](1 ))
13
+
14
+ println(patternMatch[String ](" abc" )(using (s : Any ) => {
15
+ if s.isInstanceOf [S ] then Some [s.type & Matcher [String ]](s.asInstanceOf [s.type & Matcher [String ]]) else None }))
16
+ println(patternMatch[String ](" abc" )(using (s : Any ) => {
17
+ if s.isInstanceOf [MS ] then Some [s.type & Matcher [String ]](s.asInstanceOf [s.type & Matcher [String ]]) else None }))
18
+ println(patternMatch[String ](" abc" )(using (s : Any ) => {
19
+ if s.isInstanceOf [S2 ] then Some [s.type & Matcher [String ]](s.asInstanceOf [s.type & Matcher [String ]]) else None }))
20
+ println(patternMatch[String ](" abc" )(using (s : Any ) => {
21
+ if s.isInstanceOf [MS2 ] then Some [s.type & Matcher [String ]](s.asInstanceOf [s.type & Matcher [String ]]) else None }))
22
+ }
You can’t perform that action at this time.
0 commit comments