Skip to content

Commit a964745

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 31d55e0 commit a964745

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

compiler/test/dotc/pos-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ i5720.scala
4444
# Tuples
4545
toexproftuple.scala
4646
i7580.scala
47+
i12721.scala
4748

4849
# Nullability
4950
nullable.scala

compiler/test/dotc/run-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ tuple-zip.scala
2222
tuples1.scala
2323
tuples1a.scala
2424
tuples1b.scala
25+
toList.scala
2526
typeCheckErrors.scala
2627
typeclass-derivation-doc-example.scala
2728
typeclass-derivation1.scala

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)