Skip to content

Commit b911e17

Browse files
Move toTuple to Tuple companion
1 parent 1d28875 commit b911e17

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

library/src/dotty/DottyPredef.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,4 @@ object DottyPredef {
3838

3939
inline def the[T] given (x: T): x.type = x
4040

41-
def (p: P) toTuple[P <: Product] given (m: scala.deriving.Mirror.ProductOf[P]): m.MirroredElemTypes =
42-
Tuple.fromArray(p.productIterator.toArray).asInstanceOf[m.MirroredElemTypes]
4341
}

library/src/scala/Tuple.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ object Tuple {
109109
def fromProduct(product: Product): Tuple =
110110
runtime.DynamicTuple.dynamicFromProduct[Tuple](product)
111111

112+
def fromProductTyped[P <: Product](p: P) given (m: scala.deriving.Mirror.ProductOf[P]): m.MirroredElemTypes =
113+
Tuple.fromArray(p.productIterator.toArray).asInstanceOf[m.MirroredElemTypes]
112114
}
113115

114116
/** Tuple of arbitrary non-zero arity */

tests/neg/product-to-tuple.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
case class Foo(x: Int, y: String)
22

33
val x = Foo(1, "2")
4-
val y: (Int, Boolean) = x.toTuple // error
4+
val y: (Int, Boolean) = Tuple.fromProductTyped(x) // error
55

66
case class Bar[I <: Int, S <: String](x: I, y: S)
77
val a: Bar[1, "2"] = Bar(1, "2")
8-
val b: (1, "3") = a.toTuple // error
8+
val b: (1, "3") = Tuple.fromProductTyped(a) // error

tests/pos/product-to-tuple.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
case class Foo(x: Int, y: String)
22

33
val x = Foo(1, "2")
4-
val y: (Int, String) = x.toTuple
4+
val y: (Int, String) = Tuple.fromProductTyped(x)
55

66
case class Bar[I <: Int, S <: String](x: I, y: S)
77
val a: Bar[1, "2"] = Bar(1, "2")
8-
val b: (1, "2") = a.toTuple
8+
val b: (1, "2") = Tuple.fromProductTyped(a)

0 commit comments

Comments
 (0)