Skip to content

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

@eejbyfeldt

Description

@eejbyfeldt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions