Skip to content

Commit ea1f66a

Browse files
committed
Hide old Tuple.toList and implement as extension
This should in theory be backwards TASTy compatible. Fixes #12721
1 parent 0cdc242 commit ea1f66a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

library/src/scala/Tuple.scala

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ sealed trait Tuple extends Product {
1111
inline def toArray: Array[Object] =
1212
runtime.Tuples.toArray(this)
1313

14+
// NOTE: Replaced by `toList` extension method in the `Tuple` object.
15+
// Kept this version of the method as `private[scala]` to be
16+
// able to unpickle older TASTy files.
17+
// TODO: When we can break TASTy compat, replace this method with one that has the following signature
18+
// `inline def toList[This >: this.type <: Tuple]: List[Union[This]]`
19+
// and remove the extension method in the `Tuple` object.
1420
/** Create a copy this tuple as a List */
15-
inline def toList[This >: this.type <: Tuple]: List[Union[This]] =
16-
this.productIterator.toList.asInstanceOf[List[Union[This]]]
21+
private[scala] inline def toList: List[Union[this.type]] =
22+
this.productIterator.toList.asInstanceOf[List[Union[this.type]]]
1723

1824
/** Create a copy this tuple as an IArray */
1925
inline def toIArray: IArray[Object] =
@@ -231,6 +237,13 @@ object Tuple {
231237

232238
def fromProductTyped[P <: Product](p: P)(using m: scala.deriving.Mirror.ProductOf[P]): m.MirroredElemTypes =
233239
runtime.Tuples.fromProduct(p).asInstanceOf[m.MirroredElemTypes]
240+
241+
// TODO: When we can break TASTy compat, move this method to `Tuple` class and use the following signature
242+
// `inline def toList[This >: this.type <: Tuple]: List[Union[This]]`
243+
/** Create a copy this tuple as a List */
244+
extension [This <: Tuple](inline tuple: This)
245+
inline def toList: List[Union[This]] =
246+
tuple.productIterator.toList.asInstanceOf[List[Union[This]]]
234247
}
235248

236249
/** A tuple of 0 elements */

0 commit comments

Comments
 (0)