diff options
-rw-r--r-- | src/library/scala/collection/mutable/ArrayOps.scala | 7 | ||||
-rw-r--r-- | test/files/run/t2788.check | 1 | ||||
-rw-r--r-- | test/files/run/t2788.scala | 3 |
3 files changed, 8 insertions, 3 deletions
diff --git a/src/library/scala/collection/mutable/ArrayOps.scala b/src/library/scala/collection/mutable/ArrayOps.scala index 98d635ecee..a465e9152c 100644 --- a/src/library/scala/collection/mutable/ArrayOps.scala +++ b/src/library/scala/collection/mutable/ArrayOps.scala @@ -64,10 +64,11 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with Parallelizable[Pa * @param asArray A function that converts elements of this array to rows - arrays of type `U`. * @return An array obtained by concatenating rows of this array. */ - def flatten[U](implicit asArray: T => /*<:<!!!*/ Array[U]): Array[U] = { - val b = rowBuilder[U] + def flatten[U, To](implicit asTrav: T => collection.Traversable[U], m: ClassManifest[U]): Array[U] = { + val b = Array.newBuilder[U] + b.sizeHint(map{case is: IndexedSeq[_] => is.size case _ => 0} sum) for (xs <- this) - b ++= asArray(xs) + b ++= asTrav(xs) b.result } diff --git a/test/files/run/t2788.check b/test/files/run/t2788.check new file mode 100644 index 0000000000..684f5f616c --- /dev/null +++ b/test/files/run/t2788.check @@ -0,0 +1 @@ +List(1, 2)
\ No newline at end of file diff --git a/test/files/run/t2788.scala b/test/files/run/t2788.scala new file mode 100644 index 0000000000..7cc5031a59 --- /dev/null +++ b/test/files/run/t2788.scala @@ -0,0 +1,3 @@ +object Test extends Application { + println(Array(Some(1), None, Some(2)).flatten.toList) +}
\ No newline at end of file |