-
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.
synthesize mirrors for small generic tuples, redux
- handles generic tuples of different arity
- Loading branch information
1 parent
9d2d194
commit 352cc6f
Showing
12 changed files
with
121 additions
and
14 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- Error: tests/neg/i14127.scala:6:55 ---------------------------------------------------------------------------------- | ||
6 | *: Int *: Int *: Int *: Int *: Int *: EmptyTuple)]] // error | ||
| ^ | ||
|No given instance of type deriving.Mirror.Of[(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | ||
| Int | ||
|, Int, Int)] was found for parameter x of method summon in object Predef. Failed to synthesize an instance of type deriving.Mirror.Of[(Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | ||
| Int | ||
|, Int, Int)]: | ||
| * class *: is not a generic product because it reduces to a tuple with arity 23, expected arity <= 22 | ||
| * class *: is not a generic sum because it does not have subclasses |
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,6 @@ | ||
import scala.deriving.Mirror | ||
|
||
val mT23 = summon[Mirror.Of[( | ||
Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int | ||
*: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int | ||
*: Int *: Int *: Int *: Int *: Int *: EmptyTuple)]] // error |
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,14 @@ | ||
import scala.deriving.Mirror | ||
|
||
@main def Test = | ||
val mISB = summon[Mirror.Of[Int *: String *: Boolean *: EmptyTuple]] | ||
assert(mISB.fromProduct((1, "foo", true)) == (1, "foo", true)) | ||
|
||
val mT22 = summon[Mirror.Of[( | ||
Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int | ||
*: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int *: Int | ||
*: Int *: Int *: Int *: Int *: EmptyTuple)]] | ||
|
||
// tuple of 22 elements | ||
val t22 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22) | ||
assert(mT22.fromProduct(t22) == t22) |
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,18 @@ | ||
import scala.deriving._ | ||
|
||
case class Foo(x: Int, y: String) | ||
|
||
def toTuple[T <: Product](x: T)(using m: Mirror.ProductOf[T], mt: Mirror.ProductOf[m.MirroredElemTypes]) = | ||
mt.fromProduct(x) | ||
|
||
@main def Test = { | ||
val m = summon[Mirror.ProductOf[Foo]] | ||
val mt1 = summon[Mirror.ProductOf[(Int, String)]] | ||
type R = (Int, String) | ||
val mt2 = summon[Mirror.ProductOf[R]] | ||
val mt3 = summon[Mirror.ProductOf[m.MirroredElemTypes]] | ||
|
||
val f = Foo(1, "foo") | ||
val g: (Int, String) = toTuple(f)// (using m, mt1) | ||
assert(g == (1, "foo")) | ||
} |