Named tuple type alias breaks compilation

scala someFn.tupled works when calling with anonymous named tuples, example

val point = (x = 1.0, y = 2.0)

however if the named tuple was defined with a type alias like

type Point = (x: Double, y: Double)
val point: Point = (x = 1.0, y = 2.0)

then compilation breaks when point is passed to someFn.tupled

Here is an full example you can test in a scala 3.5 worksheet, notice that testA and testB are the same tuple reference, but the second used type alias

type Rekto = (x: Double, y: Double, w: Double, h: Double, l: Boolean)

val testA = (x = 1.0, y = 2.0, w = 3.0, h = 4.0, l = true)

val testB: Rekto = testA // <= same as testA

def pinta(x: Double, y: Double, w: Double, h: Double, l: Boolean): Unit =
  println(s"pinta: $x, $y, $w, $h, $l")

// WORKS
pinta.tupled(testA)

// DOES NOT WORK
// Found:    (MdocApp.this.testB : MdocApp.this.Rekto)
// Required: (Double, Double, Double, Double, Boolean)
pinta.tupled(testB)

Seems not implemented in release versions. Tested in Scala 3.5.2:

type Person = (name: String, age: Int)
val Bob: Person = (name = "Bob", age = 33)
val x: (String, Int) = Bob

That’s directly from the docs at:

https://dotty.epfl.ch/docs/reference/other-new-features/named-tuples.html

It says there:

A .toTuple selection is inserted implicitly by the compiler if it encounters a named tuple but the expected type is a regular tuple.

But the example code does not work, with the same error as here.

I would just wait, because the docs say “Starting in Scala 3.6…” :smile:

2 Likes