From 0308ae88026a4a8d427d1a9156c31c0ff8dd2561 Mon Sep 17 00:00:00 2001 From: Aleksandar Prokopec Date: Wed, 15 Aug 2012 15:50:03 +0200 Subject: Fixes SI-6150. Removes the `VectorReusableCBF` and pattern matching on it in optimized `Vector` methods. Instead, we now have a new `ReusableCBF` instance in `IndexedSeq` and check for equality when trying to optimize `:+`, `+:` and `updated`. This overridden `ReusableCBF` is used by `IndexedSeq`, `immutable.IndexedSeq` and `immutable.Vector`. The net effect is that calling `:+` and similar methods on a `Vector` instance with a `CBF` that came from `IndexedSeq` or somewhere lower in the hierarchy will always create a `Vector` using the optimized method. --- test/files/run/t6150.scala | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/files/run/t6150.scala (limited to 'test/files/run/t6150.scala') diff --git a/test/files/run/t6150.scala b/test/files/run/t6150.scala new file mode 100644 index 0000000000..1b3de0c50a --- /dev/null +++ b/test/files/run/t6150.scala @@ -0,0 +1,34 @@ + + + +import collection._ + + + +object Test extends App { + + val cbf1 = implicitly[generic.CanBuildFrom[Vector[Int], Int, IndexedSeq[Int]]] + val cbf2 = implicitly[generic.CanBuildFrom[immutable.IndexedSeq[Int], Int, IndexedSeq[Int]]] + val cbf3 = implicitly[generic.CanBuildFrom[IndexedSeq[Int], Int, IndexedSeq[Int]]] + + def check[C](v: C) = { + assert(v == Vector(1, 2, 3, 4)) + assert(v.isInstanceOf[Vector[_]]) + } + + val v = immutable.Vector(1, 2, 3) + + check(v.:+(4)(cbf1)) + check(v.:+(4)(cbf2)) + check(v.:+(4)(cbf3)) + + val iiv: immutable.IndexedSeq[Int] = immutable.Vector(1, 2, 3) + + check(iiv.:+(4)(cbf2)) + check(iiv.:+(4)(cbf3)) + + val iv: IndexedSeq[Int] = immutable.Vector(1, 2, 3) + + check(iv.:+(4)(cbf3)) + +} -- cgit v1.2.3