diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-18 09:14:37 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-18 09:14:37 -0700 |
commit | a4b7928c55c362ce489ae9ba480d2b31844ce0f1 (patch) | |
tree | 83c47400784e9ce55daa417ff4d5d23e1bae3bcb /src | |
parent | cb342c8807a25b881468a9f073cb756973df7561 (diff) | |
parent | b6b360058bc49d7c4308b153b9989bc1aeac4f53 (diff) | |
download | scala-a4b7928c55c362ce489ae9ba480d2b31844ce0f1.tar.gz scala-a4b7928c55c362ce489ae9ba480d2b31844ce0f1.tar.bz2 scala-a4b7928c55c362ce489ae9ba480d2b31844ce0f1.zip |
Merge pull request #940 from axel22/issue/5937
SI-5937: Vector updated, +:, and :+ ignore provided builder, breaking type safety
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/immutable/Vector.scala | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/library/scala/collection/immutable/Vector.scala b/src/library/scala/collection/immutable/Vector.scala index d100bf93df..4dfe147a65 100644 --- a/src/library/scala/collection/immutable/Vector.scala +++ b/src/library/scala/collection/immutable/Vector.scala @@ -18,8 +18,14 @@ import scala.collection.parallel.immutable.ParVector /** Companion object to the Vector class */ object Vector extends SeqFactory[Vector] { + private[collection] class VectorReusableCBF extends GenericCanBuildFrom[Nothing] { + override def apply() = newBuilder[Nothing] + } + + private val VectorReusableCBF: GenericCanBuildFrom[Nothing] = new VectorReusableCBF + @inline implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Vector[A]] = - ReusableCBF.asInstanceOf[CanBuildFrom[Coll, A, Vector[A]]] + VectorReusableCBF.asInstanceOf[CanBuildFrom[Coll, A, Vector[A]]] def newBuilder[A]: Builder[A, Vector[A]] = new VectorBuilder[A] private[immutable] val NIL = new Vector[Nothing](0, 0, 0) @inline override def empty[A]: Vector[A] = NIL @@ -140,19 +146,19 @@ override def companion: GenericCompanion[Vector] = Vector // SeqLike api - @inline override def updated[B >: A, That](index: Int, elem: B)(implicit bf: CanBuildFrom[Vector[A], B, That]): That = { - // just ignore bf - updateAt(index, elem).asInstanceOf[That] + @inline override def updated[B >: A, That](index: Int, elem: B)(implicit bf: CanBuildFrom[Vector[A], B, That]): That = bf match { + case _: Vector.VectorReusableCBF => updateAt(index, elem).asInstanceOf[That] // just ignore bf + case _ => super.updated(index, elem)(bf) } - @inline override def +:[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Vector[A], B, That]): That = { - // just ignore bf - appendFront(elem).asInstanceOf[That] + @inline override def +:[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Vector[A], B, That]): That = bf match { + case _: Vector.VectorReusableCBF => appendFront(elem).asInstanceOf[That] // just ignore bf + case _ => super.+:(elem)(bf) } - @inline override def :+[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Vector[A], B, That]): That = { - // just ignore bf - appendBack(elem).asInstanceOf[That] + @inline override def :+[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Vector[A], B, That]): That = bf match { + case _: Vector.VectorReusableCBF => appendBack(elem).asInstanceOf[That] // just ignore bf + case _ => super.:+(elem)(bf) } override def take(n: Int): Vector[A] = { |