Skip to content

Commit 5d158f8

Browse files
committed
Fix Tuple.toList return type
This method failed for any subtype of `Tuple`. It only worked for `Tuple` and `TupleN` as these define their own `toList`. Fixes #12721
1 parent 75556ad commit 5d158f8

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

library/src/scala/Tuple.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ sealed trait Tuple extends Product {
1212
runtime.Tuples.toArray(this)
1313

1414
/** Create a copy this tuple as a List */
15-
inline def toList: List[Union[this.type]] =
16-
this.productIterator.toList
17-
.asInstanceOf[List[Union[this.type]]]
15+
inline def toList[This >: this.type <: Tuple]: List[Union[This]] =
16+
this.productIterator.toList.asInstanceOf[List[Union[This]]]
1817

1918
/** Create a copy this tuple as an IArray */
2019
inline def toIArray: IArray[Object] =

tests/pos/i12721.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def bar(t: Any): Int = 1
2+
def foo(t: AnyRef): Unit =
3+
(??? : Tuple).toList.map(bar)
4+
(??? : EmptyTuple).toList.map(bar)
5+
(??? : NonEmptyTuple).toList.map(bar)
6+
(??? : *:[?, ?]).toList.map(bar)
7+
(??? : (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int)).toList.map(bar)

0 commit comments

Comments
 (0)