summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiark Rompf <tiark.rompf@epfl.ch>2010-03-16 23:06:10 +0000
committerTiark Rompf <tiark.rompf@epfl.ch>2010-03-16 23:06:10 +0000
commitc2a9a308cce58d1a1fec703235cdce4e7438e0a0 (patch)
treecd9b5931cfe8c33a1e089778a44b6ecbbc029dc7
parent704aa0362f48c26f3cf0b166d3a64c75f5387e8b (diff)
downloadscala-c2a9a308cce58d1a1fec703235cdce4e7438e0a0.tar.gz
scala-c2a9a308cce58d1a1fec703235cdce4e7438e0a0.tar.bz2
scala-c2a9a308cce58d1a1fec703235cdce4e7438e0a0.zip
closes #3112. no review.
-rw-r--r--src/library/scala/collection/immutable/Vector.scala29
-rw-r--r--test/files/run/t3112.check4
-rw-r--r--test/files/run/t3112.scala11
3 files changed, 32 insertions, 12 deletions
diff --git a/src/library/scala/collection/immutable/Vector.scala b/src/library/scala/collection/immutable/Vector.scala
index 1326768090..6fb2aee054 100644
--- a/src/library/scala/collection/immutable/Vector.scala
+++ b/src/library/scala/collection/immutable/Vector.scala
@@ -108,34 +108,38 @@ override def companion: GenericCompanion[Vector] = Vector
}
override def take(n: Int): Vector[A] = {
- if (n < 0) throw new IllegalArgumentException(n.toString)
- if (startIndex + n < endIndex) {
+ if (n <= 0)
+ Vector.empty
+ else if (startIndex + n < endIndex)
dropBack0(startIndex + n)
- } else
+ else
this
}
override def drop(n: Int): Vector[A] = {
- if (n < 0) throw new IllegalArgumentException(n.toString)
- if (startIndex + n < endIndex) {
+ if (n <= 0)
+ this
+ else if (startIndex + n < endIndex)
dropFront0(startIndex + n)
- } else
+ else
Vector.empty
}
override def takeRight(n: Int): Vector[A] = {
- if (n < 0) throw new IllegalArgumentException(n.toString)
- if (endIndex - n > startIndex) {
+ if (n <= 0)
+ Vector.empty
+ else if (endIndex - n > startIndex)
dropFront0(endIndex - n)
- } else
+ else
this
}
override def dropRight(n: Int): Vector[A] = {
- if (n < 0) throw new IllegalArgumentException(n.toString)
- if (endIndex - n > startIndex) {
+ if (n <= 0)
+ this
+ else if (endIndex - n > startIndex)
dropBack0(endIndex - n)
- } else
+ else
Vector.empty
}
@@ -843,6 +847,7 @@ private[immutable] trait VectorPointer[T] {
final def copyOf(a: Array[AnyRef]) = {
//println("copy")
+ if (a eq null) println ("NULL")
val b = new Array[AnyRef](a.length)
Platform.arraycopy(a, 0, b, 0, a.length)
b
diff --git a/test/files/run/t3112.check b/test/files/run/t3112.check
new file mode 100644
index 0000000000..a95644c82c
--- /dev/null
+++ b/test/files/run/t3112.check
@@ -0,0 +1,4 @@
+Vector()
+Vector()
+Vector()
+Vector() \ No newline at end of file
diff --git a/test/files/run/t3112.scala b/test/files/run/t3112.scala
new file mode 100644
index 0000000000..eb8eec6327
--- /dev/null
+++ b/test/files/run/t3112.scala
@@ -0,0 +1,11 @@
+// #3112
+object Test {
+
+ def main(args: Array[String]): Unit = {
+ println((Vector() ++ (0 until 32)) take 0) // works
+ println((Vector() ++ (0 until 33)) take 0) // error
+ println((Vector() ++ (0 until 32)) takeRight 0) // works
+ println((Vector() ++ (0 until 33)) takeRight 0) // error
+ }
+
+} \ No newline at end of file