scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Mirror are available for NamedTuples when names and fields are not fully known

Open eejbyfeldt opened this issue 2 weeks ago • 0 comments

Compiler version

3.7.4, 3.8.1-RC1-bin-20251125-ae54faa-NIGHTLY

Minimized code

import scala.deriving.Mirror
import NamedTuple.NamedTuple

object test {
  def f[N <: Tuple, V <: Tuple] =
    summon[Mirror.ProductOf[NamedTuple[N, V]]]
}

Output

scala> test.f
val res0:
  scala.deriving.Mirror.Product{
    type MirroredMonoType = NamedTuple.NamedTuple[Tuple, Tuple];
      type MirroredType = NamedTuple.NamedTuple[Tuple, Tuple];
      type MirroredLabel = "NamedTuple";
      type MirroredElemTypes = EmptyTuple.type;
      type MirroredElemLabels = EmptyTuple.type
  } = scala.runtime.TupleMirror@5d94ac8a

scala> test.f[("a", "b"),(Int, String)]
val res1:
  scala.deriving.Mirror.Product{
    type MirroredMonoType = (a : Int, b : String);
      type MirroredType = (a : Int, b : String);
      type MirroredLabel = "NamedTuple";
      type MirroredElemTypes = EmptyTuple.type;
      type MirroredElemLabels = EmptyTuple.type
  } = scala.runtime.TupleMirror@6aa9a93b

scala> test.f[EmptyTuple, EmptyTuple].fromProduct(EmptyTuple)
val res1: NamedTuple.NamedTuple[EmptyTuple, EmptyTuple] = ()

scala> test.f[("a", "b"), (Int, String)].fromProduct((23, "xyz"))
java.lang.IllegalArgumentException: expected Product with 0 elements, got 2
  at scala.runtime.TupleMirror.fromProduct(TupleMirror.scala:13)
  at scala.runtime.TupleMirror.fromProduct(TupleMirror.scala:11)
  ... 30 elided

Expectation

Should not compile saying that it unable to derive a mirror for this case.

eejbyfeldt avatar Nov 25 '25 13:11 eejbyfeldt