Skip to content

Missing arity check in fromProduct for Tuples #15399

Closed
@nicolasstucki

Description

@nicolasstucki

Compiler version

438dfb0

Minimized code

@main def Test =
  val tup2Mirror = summon[scala.deriving.Mirror.Of[(Int, Int)]]
  val tup2a: (Int, Int) = tup2Mirror.fromProduct((1, 2, 3)) // fails silently and creates (1, 2)
  println(tup2a)
  val tup2b: (Int, Int) = tup2Mirror.fromProduct(Tuple(1)) // crashes with index out of bounds
  println(tup2b)

Output

Exception in thread "main" java.lang.IndexOutOfBoundsException: 1 is out of bounds (min 0, max 0)
        at scala.Product1.productElement(Product1.scala:42)
        at scala.Product1.productElement$(Product1.scala:40)
        at scala.Tuple1.productElement(Tuple1.scala:23)
        at Test$package$$anon$1.fromProduct(Test.scala:4)
        at Test$package$$anon$1.fromProduct(Test.scala:4)
        at Test$package$.Test(Test.scala:6)
        at Test.main(Test.scala:3)

Expectation

fromProduct should assert that the arity of the given tuple is correct. It should fail with a meaningful error message.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions