-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalize when verifying if TypeTestCasts are unchecked
- Loading branch information
1 parent
05114dd
commit abb6909
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import scala.reflect.TypeTest | ||
|
||
type Matcher[A] = A match { case String => A } | ||
|
||
def patternMatch[A](a: Any)(using tt: TypeTest[Any, Matcher[A]]): Option[Matcher[A]] = { | ||
// type T = RDF.Triple[Rdf] | ||
a match { | ||
case res: Matcher[A] => Some(res) | ||
case _ => None | ||
} | ||
} | ||
|
||
def patternMatchWithAlias[A](a: Any)(using tt: TypeTest[Any, Matcher[A]]): Option[Matcher[A]] = { | ||
type T = Matcher[A] | ||
a match { | ||
case res: T => Some(res) | ||
case _ => None | ||
} | ||
} | ||
|
||
type S = String | ||
type MS = Matcher[S] | ||
|
||
type S2 = MS | ||
type MS2 = Matcher[S2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//> using options -Xfatal-warnings -deprecation -feature | ||
|
||
@main def main = { | ||
println(patternMatch[String]("abc")) | ||
println(patternMatchWithAlias[String]("abc")) | ||
println(patternMatch[String]("abc")(using (s: Any) => { | ||
if s.isInstanceOf[Matcher[String]] then Some[s.type & Matcher[String]](s.asInstanceOf[s.type & Matcher[String]]) else None })) | ||
println(patternMatchWithAlias[String]("abc")(using (s: Any) => { | ||
if s.isInstanceOf[Matcher[String]] then Some[s.type & Matcher[String]](s.asInstanceOf[s.type & Matcher[String]]) else None })) | ||
|
||
println(patternMatch[String](1)) | ||
println(patternMatchWithAlias[String](1)) | ||
|
||
println(patternMatch[String]("abc")(using (s: Any) => { | ||
if s.isInstanceOf[S] then Some[s.type & Matcher[String]](s.asInstanceOf[s.type & Matcher[String]]) else None})) | ||
println(patternMatch[String]("abc")(using (s: Any) => { | ||
if s.isInstanceOf[MS] then Some[s.type & Matcher[String]](s.asInstanceOf[s.type & Matcher[String]]) else None})) | ||
println(patternMatch[String]("abc")(using (s: Any) => { | ||
if s.isInstanceOf[S2] then Some[s.type & Matcher[String]](s.asInstanceOf[s.type & Matcher[String]]) else None})) | ||
println(patternMatch[String]("abc")(using (s: Any) => { | ||
if s.isInstanceOf[MS2] then Some[s.type & Matcher[String]](s.asInstanceOf[s.type & Matcher[String]]) else None})) | ||
} |