Issue with transformed tuples in an inline function (possibly compiler bug?) #16607
-
Hi, I'm forced to use the inline matches that destruct and re-construct the tuples from the mirror. Both functions should be identical, but the bottom one does not compile. The usage of As a side note: it's very hard to debug these things - how could I have the compiler tell me the type of import scala.deriving.*
import scala.compiletime.*
object Test {
class Reader[A]()
given Reader[Int] = Reader()
given Reader[Double] = Reader()
type PutReader[T] = T match {
case (a, b) =>
Reader[b]
}
inline def test[
A,
](using
aMirror: Mirror.ProductOf[A],
): Unit = {
inline erasedValue[aMirror.MirroredElemLabels] match {
case _: (head *: tail) =>
type ALabels = head *: tail
inline erasedValue[aMirror.MirroredElemTypes] match {
case _: (head *: tail) =>
type ATypes = head *: tail
type AMap = Tuple.Zip[ALabels, ATypes]
type Readers = Tuple.Map[AMap, PutReader]
summonAll[Readers] // works
}
}
}
inline def brokenTest[
A,
](using
aMirror: Mirror.ProductOf[A],
): Unit = {
type AMap = Tuple.Zip[aMirror.MirroredElemLabels, aMirror.MirroredElemTypes]
type Readers = Tuple.Map[AMap, PutReader]
summonAll[Readers] // doesn't work
}
case class Foo(a: Int, b: Double)
test[Foo]
brokenTest[Foo]
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This code works: import scala.deriving.*
import scala.compiletime.*
object Test {
class Reader[A]()
given Reader[Int] = Reader()
given Reader[Double] = Reader()
type PutReader[T] = T match {
case (a, b) =>
Reader[b]
}
inline def brokenTest[
A,
](using
aMirror: Mirror.ProductOf[A],
): Unit = {
type AMap = Tuple.Zip[aMirror.MirroredElemLabels, aMirror.MirroredElemTypes] & NonEmptyTuple
type Readers = Tuple.Map[AMap, PutReader]
summonAll[Readers] // doesn't work
}
case class Foo(a: Int, b: Double)
brokenTest[Foo]
} I added It seems that the compiler does not type properly The cause seems to be Even if it's annoying, it looks "normal" to me since you don't "know" the specific |
Beta Was this translation helpful? Give feedback.
-
Thanks! I applied similar changes in the code I used to create this minimal test case and it works. As you mention, it is indeed strange that the types of What's strange is that I can understand if the function itself failed to compile, but it only fails to compile when used, despite being used on a non-empty tuple. |
Beta Was this translation helpful? Give feedback.
This code works:
I added
& NonEmptyTuple
at line 20 to explicitly tell the compiler thatAMap
is aNonEmptyTuple
(note that it is unsafe b…