From 4380911a32eb7fa99faf5fea4ba5f9ad6a3a5258 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 19 Mar 2011 17:32:37 +0000 Subject: Removed long deprecated and obscure CloneableCo... Removed long deprecated and obscure CloneableCollection. Discovered we have a scala.collection.mutable.Cloneable which does not extend java.lang.Cloneable, which is why Array is not considered cloneable. That seems wrong, but to be conservative I gave Array the Cloneable interface without altering the scala trait. Also, if @serializable is deprecated in favor of Serializable, should not @cloneable be deprecated analogously? Closes #4307, and a commit-question review by rytz. --- .../scala/tools/nsc/backend/jvm/GenJVM.scala | 6 +-- src/library/scala/Array.scala | 47 ++++++++-------------- .../scala/collection/mutable/Cloneable.scala | 3 +- .../collection/mutable/CloneableCollection.scala | 22 ---------- test/files/pos/array-interfaces.scala | 9 +++++ 5 files changed, 30 insertions(+), 57 deletions(-) delete mode 100644 src/library/scala/collection/mutable/CloneableCollection.scala create mode 100644 test/files/pos/array-interfaces.scala diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index c97fdbf58e..9a1bafa27f 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -237,13 +237,13 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid { for (annot <- c.symbol.annotations) annot match { case AnnotationInfo(tp, _, _) if tp.typeSymbol == SerializableAttr => - parents = parents ::: List(SerializableClass.tpe) + parents :+= SerializableClass.tpe case AnnotationInfo(tp, _, _) if tp.typeSymbol == CloneableAttr => - parents = parents ::: List(CloneableClass.tpe) + parents :+= CloneableClass.tpe case AnnotationInfo(tp, Literal(const) :: _, _) if tp.typeSymbol == SerialVersionUIDAttr => serialVUID = Some(const.longValue) case AnnotationInfo(tp, _, _) if tp.typeSymbol == RemoteAttr => - parents = parents ::: List(RemoteInterface.tpe) + parents :+= RemoteInterface.tpe isRemoteClass = true case _ => } diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala index 7183d9a473..1bdc5b23c9 100644 --- a/src/library/scala/Array.scala +++ b/src/library/scala/Array.scala @@ -415,7 +415,7 @@ object Array extends FallbackArrayBuilding { def unapplySeq[T](x: Array[T]): Option[IndexedSeq[T]] = if (x == null) None else Some(x.toIndexedSeq) // !!! the null check should to be necessary, but without it 2241 fails. Seems to be a bug - // in pattern matcher. + // in pattern matcher. @PP: I noted in #4364 I think the behavior is correct. /** Creates an array containing several copies of an element. * @@ -483,7 +483,7 @@ object Array extends FallbackArrayBuilding { * @author Martin Odersky * @version 1.0 */ -final class Array[T](_length: Int) extends java.io.Serializable { +final class Array[T](_length: Int) extends java.io.Serializable with java.lang.Cloneable { /** Multidimensional array creation */ @deprecated("use `Array.ofDim' instead") @@ -545,43 +545,28 @@ final class Array[T](_length: Int) extends java.io.Serializable { def length: Int = throw new Error() /** The element at given index. - *

- * Indices start a `0`; `xs.apply(0)` is the first - * element of array `xs`. - *

- *

- * Note the indexing syntax `xs(i)` is a shorthand for - * `xs.apply(i)`. - *

* - * @param i the index - * @throws ArrayIndexOutOfBoundsException if `i < 0` or - * `length <= i` + * Indices start at `0`; `xs.apply(0)` is the first element of array `xs`. + * Note the indexing syntax `xs(i)` is a shorthand for `xs.apply(i)`. + * + * @param i the index + * @return the element at the given index + * @throws ArrayIndexOutOfBoundsException if `i < 0` or `length <= i` */ def apply(i: Int): T = throw new Error() - /**

- * Update the element at given index. - *

- *

- * Indices start a `0`; `xs.apply(0)` is the first - * element of array `xs`. - *

- *

- * Note the indexing syntax `xs(i) = x` is a shorthand - * for `xs.update(i, x)`. - *

+ /** Update the element at given index. + * + * Indices start at `0`; `xs.apply(0)` is the first element of array `xs`. + * Note the indexing syntax `xs(i)` is a shorthand for `xs.apply(i)`. * - * @param i the index - * @param x the value to be written at index `i` - * @throws ArrayIndexOutOfBoundsException if `i < 0` or - * `length <= i` + * @param i the index + * @param x the value to be written at index `i` + * @throws ArrayIndexOutOfBoundsException if `i < 0` or `length <= i` */ def update(i: Int, x: T) { throw new Error() } - /**

- * Clone the Array. - *

+ /** Clone the Array. * * @return A clone of the Array. */ diff --git a/src/library/scala/collection/mutable/Cloneable.scala b/src/library/scala/collection/mutable/Cloneable.scala index 15c245fde0..28bf2ceb8e 100644 --- a/src/library/scala/collection/mutable/Cloneable.scala +++ b/src/library/scala/collection/mutable/Cloneable.scala @@ -18,6 +18,7 @@ package mutable * @tparam A Type of the elements contained in the collection, covariant and with reference types as upperbound. */ @cloneable -trait Cloneable[+A <: AnyRef] { +trait Cloneable[+A <: AnyRef] { + // !!! why doesn't this extend java.lang.Cloneable? override def clone: A = super.clone().asInstanceOf[A] } diff --git a/src/library/scala/collection/mutable/CloneableCollection.scala b/src/library/scala/collection/mutable/CloneableCollection.scala deleted file mode 100644 index 8659842b71..0000000000 --- a/src/library/scala/collection/mutable/CloneableCollection.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.collection -package mutable - -/** The J2ME version of the library defined this trait with a `clone` - * method to substitute for the lack of `Object.clone` there. - * - * @since 2.6 - */ -@deprecated("use Cloneable instead") -trait CloneableCollection { - override def clone(): AnyRef = super.clone() -} diff --git a/test/files/pos/array-interfaces.scala b/test/files/pos/array-interfaces.scala new file mode 100644 index 0000000000..70cafd2bb1 --- /dev/null +++ b/test/files/pos/array-interfaces.scala @@ -0,0 +1,9 @@ +object s { + def f(x: Cloneable) = () + def g(x: java.io.Serializable) = () + + def main(args: Array[String]): Unit = { + f(args) + g(args) + } +} \ No newline at end of file -- cgit v1.2.3