-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea27651
commit 9c62e41
Showing
12 changed files
with
104 additions
and
7 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
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
This file was deleted.
Oops, something went wrong.
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 @@ | ||
object MyBoooleanUnapply: | ||
inline def unapply(x: Int): Boolean = true | ||
|
||
object MyOptionUnapply: | ||
inline def unapply(x: Int): Option[Long] = Some(x) | ||
|
||
object MyPolyUnapply: | ||
inline def unapply[T](x: T): Option[T] = Some(x) | ||
|
||
object MySeqUnapply: | ||
inline def unapplySeq(x: Int): Seq[Int] = Seq(x, x) | ||
|
||
object MyWhiteboxUnapply: | ||
inline def unapply(x: Int) <: Option[Any] = Some(x) | ||
|
||
def test = | ||
5 match | ||
case MyBoooleanUnapply() => | ||
case MyOptionUnapply(y) => println(y) | ||
case MyPolyUnapply(a) => | ||
case MySeqUnapply(a, b) => | ||
case MyWhiteboxUnapply(x) => x: Int |
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,5 @@ | ||
|
||
object Foo { | ||
inline def unapply(x: Any): Boolean = ??? | ||
inline def unapplySeq(x: Any): Seq[Any] = ??? | ||
} |
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 @@ | ||
foo |
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,12 @@ | ||
|
||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
0 match | ||
case Succ(n) => ??? | ||
case _ => | ||
|
||
2 match | ||
case Succ(n) => assert(n == 1) | ||
} | ||
|
||
} |
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,8 @@ | ||
import scala.quoted._ | ||
|
||
object Succ: | ||
|
||
inline def unapply(n: Int): Option[Int] = ${ impl('n) } | ||
|
||
private def impl(n: Expr[Int])(using QuoteContext): Expr[Option[Int]] = | ||
'{ if $n == 0 then None else Some($n - 1)} |
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,5 @@ | ||
MyBoooleanUnapply | ||
2 | ||
3 | ||
(4,5) | ||
5 |
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,33 @@ | ||
object MyBoooleanUnapply: | ||
inline def unapply(x: Int): Boolean = true | ||
|
||
object MyOptionUnapply: | ||
inline def unapply(x: Int): Option[Long] = Some(x) | ||
|
||
object MyPolyUnapply: | ||
inline def unapply[T](x: T): Option[T] = Some(x) | ||
|
||
object MySeqUnapply: | ||
inline def unapplySeq(x: Int): Seq[Int] = Seq(x, x + 1) | ||
|
||
object MyWhiteboxUnapply: | ||
inline def unapply(x: Int) <: Option[Any] = Some(x) | ||
|
||
|
||
@main def Test = | ||
1 match | ||
case MyBoooleanUnapply() => println("MyBoooleanUnapply") | ||
|
||
2 match | ||
case MyOptionUnapply(y) => println(y) | ||
|
||
3 match | ||
case MyPolyUnapply(a) => println(a) | ||
|
||
4 match | ||
case MySeqUnapply(a, b) => println((a, b)) | ||
|
||
5 match | ||
case MyWhiteboxUnapply(x) => println(x: Int) | ||
|
||
end Test |