-
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 3f3a3da
Showing
14 changed files
with
122 additions
and
22 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 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,26 @@ | ||
object MyBoooleanUnapply: | ||
inline def unapply(x: Int): Boolean = true | ||
|
||
object MyOptionUnapply: | ||
inline def unapply(x: Int): Option[Long] = Some(x) | ||
|
||
object MyUnapplyImplicits: | ||
inline def unapply(x: Int)(using DummyImplicit): 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: Unit = | ||
val x = 5 match | ||
case MyBoooleanUnapply() => | ||
case MyOptionUnapply(y) => y: Long | ||
case MyUnapplyImplicits(y) => y: Long | ||
case MyPolyUnapply(a) => a: Int | ||
case MySeqUnapply(a, b) => (a: Int, b: Int) | ||
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,15 @@ | ||
object Test { | ||
|
||
class C(val x: Int, val y: Int) | ||
|
||
inline def unapply(c: C): Some[(Int, Int)] = Some((c.x, c.y)) | ||
|
||
} | ||
object Test2 { | ||
|
||
class C(x: Int, y: Int) | ||
|
||
inline def unapply(c: C): Option[(Int, Int)] = inline c match { | ||
case x: C => Some((1, 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 @@ | ||
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 |