summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2009-01-29 13:05:53 +0000
committerMartin Odersky <odersky@gmail.com>2009-01-29 13:05:53 +0000
commit9bf8be6db86c0931937d367995a38bddbb5ac727 (patch)
treeb4ecf99c0910f943b101a6047938649fd013d4e4
parent7b1258829de818aa1a3893b9ae33afe7cdedbbe8 (diff)
downloadscala-9bf8be6db86c0931937d367995a38bddbb5ac727.tar.gz
scala-9bf8be6db86c0931937d367995a38bddbb5ac727.tar.bz2
scala-9bf8be6db86c0931937d367995a38bddbb5ac727.zip
1.
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Definitions.scala2
-rw-r--r--src/compiler/scala/tools/nsc/symtab/StdNames.scala1
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala10
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala31
-rw-r--r--src/library/scala/Array.scala16
-rw-r--r--src/library/scala/runtime/BoxedAnyArray.scala35
-rw-r--r--src/library/scala/runtime/BoxedArray.scala38
-rw-r--r--src/library/scala/runtime/BoxedBooleanArray.scala12
-rw-r--r--src/library/scala/runtime/BoxedByteArray.scala16
-rw-r--r--src/library/scala/runtime/BoxedCharArray.scala19
-rw-r--r--src/library/scala/runtime/BoxedDoubleArray.scala14
-rw-r--r--src/library/scala/runtime/BoxedFloatArray.scala14
-rw-r--r--src/library/scala/runtime/BoxedIntArray.scala12
-rw-r--r--src/library/scala/runtime/BoxedLongArray.scala14
-rw-r--r--src/library/scala/runtime/BoxedObjectArray.scala22
-rw-r--r--src/library/scala/runtime/BoxedShortArray.scala14
-rw-r--r--src/library/scala/runtime/RichString.scala2
-rw-r--r--src/library/scala/runtime/ScalaRunTime.scala10
18 files changed, 161 insertions, 121 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
index d5afb77956..70d1a4e521 100644
--- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
@@ -93,6 +93,8 @@ trait Definitions {
lazy val TypeConstraintClass: Symbol = getClass("scala.TypeConstraint")
lazy val ManifestClass: Symbol = getClass("scala.reflect.Manifest")
lazy val ManifestModule: Symbol = getModule("scala.reflect.Manifest")
+ lazy val OptManifestClass: Symbol = getClass("scala.reflect.OptManifest")
+ lazy val NoManifest: Symbol = getModule("scala.reflect.NoManifest")
var CodeClass: Symbol = _
var CodeModule: Symbol = _
diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
index aa532f0cd3..600fcf77a8 100644
--- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala
+++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
@@ -374,6 +374,7 @@ trait StdNames {
val value = newTermName("value")
val view_ = newTermName("view")
val wait_ = newTermName("wait")
+ val withDims = newTermName("withDims")
val xml = newTermName("xml")
val zip = newTermName("zip")
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index b1d334a4b3..d9aa3e89aa 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -37,7 +37,7 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer {
* <li>For every other singleton type, the erasure of its supertype.</li>
* <li>
* For a typeref <code>scala.Array+[T]</code> where <code>T</code> is
- * an abstract type, <code>scala.runtime.BoxedArray</code>.
+ * an abstract type, <code>scala.runtime.BoxedArray[T]</code>.
* </li>
* <li>
* - For a typeref scala.Array+[T] where T is not an abstract type, scala.Array+[|T|].
@@ -592,8 +592,14 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer {
tree match {
case Apply(Select(New(tpt), name), args) if (tpt.tpe.typeSymbol == BoxedArrayClass) =>
assert(name == nme.CONSTRUCTOR);
+ val translated =
+ if (args.length >= 2) {
+ Select(gen.mkAttributedRef(ArrayModule), nme.withDims)
+ } else {
+ Select(New(TypeTree(BoxedAnyArrayClass.tpe)), name)
+ }
atPos(tree.pos) {
- Typed(Apply(Select(New(TypeTree(BoxedAnyArrayClass.tpe)), name), args), tpt)
+ Typed(Apply(translated, args), tpt)
}
case Apply(TypeApply(sel @ Select(qual, name), List(targ)), List())
if ((tree.symbol == Any_asInstanceOf || tree.symbol == Any_asInstanceOfErased)) =>
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 5a9ac741f6..ecce748314 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -2452,7 +2452,7 @@ trait Typers { self: Analyzer =>
def typedIf(cond: Tree, thenp: Tree, elsep: Tree) = {
val cond1 = checkDead(typed(cond, BooleanClass.tpe))
- if (elsep.isEmpty) {
+ if (elsep.isEmpty) { // in the future, should be unecessary
val thenp1 = typed(thenp, UnitClass.tpe)
copy.If(tree, cond1, thenp1, elsep) setType UnitClass.tpe
} else {
@@ -3406,12 +3406,15 @@ trait Typers { self: Analyzer =>
reportTypeError(tree.pos, ex)
setError(tree)
case ex: Exception =>
-// if (settings.debug.value) // @M causes cyclic reference error
-// Console.println("exception when typing "+tree+", pt = "+pt)
+ if (settings.debug.value) // @M causes cyclic reference error
+ Console.println("exception when typing "+tree+", pt = "+pt)
if ((context ne null) && (context.unit ne null) &&
(context.unit.source ne null) && (tree ne null))
logError("AT: " + (tree.pos).dbgString, ex);
throw(ex)
+ case ex: java.lang.Error =>
+ Console.println("exception when typing "+tree+", pt = "+pt)
+ throw ex
}
}
@@ -3808,14 +3811,16 @@ trait Typers { self: Analyzer =>
List()
}
- def implicitManifest(pt: Type): Tree = {
- // test below is designed so that ManifestClass need not be loaded
- // (because it's not available everywhere)
- if (pt.typeSymbol.fullNameString == "scala.reflect.Manifest")
- pt match {
- case TypeRef(_, ManifestClass, List(arg)) => manifestOfType(pos, arg)
- }
- else EmptyTree
+ def implicitManifest(pt: Type): Tree = pt match {
+ case TypeRef(_, ManifestClass, List(arg)) =>
+ manifestOfType(pos, arg)
+ case TypeRef(_, OptManifestClass, List(arg)) =>
+ val tree1 = manifestOfType(pos, arg)
+ if (tree1 == EmptyTree) gen.mkAttributedRef(NoManifest) else tree1
+ case TypeRef(_, tsym, _) if (tsym.isAbstractType) =>
+ implicitManifest(pt.bounds.lo)
+ case _ =>
+ EmptyTree
}
var tree = searchImplicit(context.implicitss, true)
@@ -3827,7 +3832,9 @@ trait Typers { self: Analyzer =>
}
/** Creates a tree that calls the relevant factory method in object
- * reflect.Manifest for type 'tp'. An EmptyTree is returned if */
+ * reflect.Manifest for type 'tp'. An EmptyTree is returned if
+ * no manifest is found
+ */
def manifestOfType(pos: Position, tp: Type): Tree = {
/** Creates a tree that calls the factory method called constructor in object reflect.Manifest */
diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala
index 0471104f62..99b3332ac6 100644
--- a/src/library/scala/Array.scala
+++ b/src/library/scala/Array.scala
@@ -35,11 +35,11 @@ object Array {
*/
def copy(src: AnyRef, srcPos: Int, dest: AnyRef, destPos: Int, length: Int) {
src match {
- case xs: runtime.BoxedArray =>
+ case xs: runtime.BoxedArray[_] =>
xs.copyTo(srcPos, dest, destPos, length)
case _ =>
dest match {
- case xs: runtime.BoxedArray =>
+ case xs: runtime.BoxedArray[_] =>
xs.copyFrom(src, srcPos, destPos, length)
case _ =>
def fillDest[T](da: Array[T], sa: Int=>T) {
@@ -254,6 +254,18 @@ object Array {
def fromFunction[A](f: (Int, Int, Int, Int, Int) => A)(n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Array[Array[Array[Array[Array[A]]]]] =
fromFunction(i => fromFunction(f(i, _, _, _, _))(n2, n3, n4, n5))(n1)
+ /** Create array with given dimensions */
+ def withDims[A](n1: Int): Array[A] =
+ new Array[A](n1)
+ def withDims[A](n1: Int, n2: Int): Array[Array[A]] =
+ fromFunction(_ => withDims[A](n2))(n1)
+ def withDims[A](n1: Int, n2: Int, n3: Int): Array[Array[Array[A]]] =
+ fromFunction(_ => withDims[A](n2, n3))(n1)
+ def withDims[A](n1: Int, n2: Int, n3: Int, n4: Int): Array[Array[Array[Array[A]]]] =
+ fromFunction(_ => withDims[A](n2, n3, n4))(n1)
+ def withDims[A](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Array[Array[Array[Array[Array[A]]]]] =
+ fromFunction(_ => withDims[A](n2, n3, n4, n5))(n1)
+
/** This method is called as a result of a pattern match { case Array(...) => } or val Array(...) = ....
*
* @param x the selector value
diff --git a/src/library/scala/runtime/BoxedAnyArray.scala b/src/library/scala/runtime/BoxedAnyArray.scala
index c7698c62d2..b30f2f2d24 100644
--- a/src/library/scala/runtime/BoxedAnyArray.scala
+++ b/src/library/scala/runtime/BoxedAnyArray.scala
@@ -22,8 +22,9 @@ import compat.Platform
* @author Martin Odersky
*/
@serializable
-final class BoxedAnyArray(val length: Int) extends BoxedArray {
+final class BoxedAnyArray[A](val length: Int) extends BoxedArray[A] {
+/*
def this(dim1: Int, dim2: Int) = {
this(dim1);
initializeWith(i => new BoxedAnyArray(dim2))
@@ -67,15 +68,16 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
private def initializeWith(elem: Int => Any) = {
for (i <- 0 until length) update(i, elem(i))
}
+*/
private var boxed = new Array[AnyRef](length)
private val hash = boxed.hashCode()
private var unboxed: AnyRef = null
private var elemClass: Class[_] = null
- def apply(index: Int): Any = synchronized {
+ def apply(index: Int): A = synchronized {
if (unboxed eq null)
- boxed(index);
+ boxed(index)
else if (elemClass eq classOf[Int])
Int.box(unboxed.asInstanceOf[Array[Int]](index))
else if (elemClass eq classOf[Double])
@@ -94,9 +96,9 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
Boolean.box(unboxed.asInstanceOf[Array[Boolean]](index))
else
unboxed.asInstanceOf[Array[AnyRef]](index)
- }
+ }.asInstanceOf[A]
- def update(index: Int, _elem: Any): Unit = synchronized {
+ def update(index: Int, _elem: A): Unit = synchronized {
val elem = _elem.asInstanceOf[AnyRef]
if (unboxed eq null)
boxed(index) = elem
@@ -207,7 +209,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
var i = 0
while (i < length) {
boxed(i) match {
- case ba: BoxedArray => boxed(i) = ba.unbox(elemClass.getComponentType())
+ case ba: BoxedArray[_] => boxed(i) = ba.unbox(elemClass.getComponentType())
case _ =>
}
i += 1
@@ -220,10 +222,9 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
unboxed
}
- override def equals(other: Any): Boolean = (
- other.isInstanceOf[BoxedAnyArray] && (this eq (other.asInstanceOf[BoxedAnyArray])) ||
+ override def equals(other: Any): Boolean =
+ other.isInstanceOf[BoxedAnyArray[_]] && (this eq (other.asInstanceOf[BoxedAnyArray[_]])) ||
(if (unboxed eq null) boxed == other else unboxed == other)
- )
override def hashCode(): Int = hash
@@ -235,14 +236,14 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
private def adapt(other: AnyRef): AnyRef =
if (this.unboxed eq null)
other match {
- case that: BoxedAnyArray =>
+ case that: BoxedAnyArray[_] =>
if (that.unboxed eq null) {
that.boxed
} else {
if (ScalaRunTime.isValueClass(that.elemClass)) unbox(that.elemClass);
that.unboxed
}
- case that: BoxedArray =>
+ case that: BoxedArray[_] =>
adapt(that.value)
case that: Array[Int] =>
unbox(ScalaRunTime.IntTag); that
@@ -265,11 +266,11 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
}
else
other match {
- case that: BoxedAnyArray =>
+ case that: BoxedAnyArray[_] =>
if (that.unboxed ne null) that.unboxed
else if (ScalaRunTime.isValueClass(this.elemClass)) that.unbox(this.elemClass)
else that.boxed
- case that: BoxedArray =>
+ case that: BoxedArray[_] =>
adapt(that.value)
case _ =>
other
@@ -291,7 +292,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
result
}
- final override def filter(p: Any => Boolean): BoxedArray = {
+ final override def filter(p: A => Boolean): BoxedArray[A] = {
val include = new Array[Boolean](length)
var len = 0
var i = 0
@@ -299,7 +300,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
if (p(this(i))) { include(i) = true; len += 1 }
i += 1
}
- val result = new BoxedAnyArray(len)
+ val result = new BoxedAnyArray[A](len)
len = 0
i = 0
while (len < result.length) {
@@ -308,8 +309,8 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
}
result
}
- override protected def newArray(length : Int, elements : Iterator[Any]) = {
- val result = new BoxedAnyArray(length)
+ override protected def newArray(length : Int, elements : Iterator[A]) = {
+ val result = new BoxedAnyArray[A](length)
var i = 0
while (elements.hasNext) {
result(i) = elements.next
diff --git a/src/library/scala/runtime/BoxedArray.scala b/src/library/scala/runtime/BoxedArray.scala
index 6affd984f8..630a6874d8 100644
--- a/src/library/scala/runtime/BoxedArray.scala
+++ b/src/library/scala/runtime/BoxedArray.scala
@@ -21,15 +21,15 @@ import collection.mutable.ArrayBuffer
* @author Martin Odersky, Stephane Micheloud
* @version 1.0
*/
-abstract class BoxedArray extends Array.Array0[Any] {
+abstract class BoxedArray[A] extends Array.Array0[A] {
/** The length of the array */
def length: Int
/** The element at given index */
- def apply(index: Int): Any
+ def apply(index: Int): A
/** Update element at given index */
- def update(index: Int, elem: Any): Unit
+ def update(index: Int, elem: A): Unit
/** Convert to Java array.
* @param elemTag Either one of the tags ".N" where N is the name of a primitive type
@@ -42,10 +42,10 @@ abstract class BoxedArray extends Array.Array0[Any] {
override def isDefinedAt(x: Int): Boolean = 0 <= x && x < length
- @serializable protected class AnyIterator extends Iterator[Any] {
+ @serializable protected class AnyIterator extends Iterator[A] {
var index = 0
def hasNext: Boolean = index < length
- def next(): Any = { val i = index; index = i + 1; apply(i) }
+ def next(): A = { val i = index; index = i + 1; apply(i) }
}
override def elements = new AnyIterator
@@ -75,7 +75,7 @@ abstract class BoxedArray extends Array.Array0[Any] {
// todo: eliminate
def subArray(from: Int, end: Int): AnyRef
- final override def map[b](f: Any => b): Array[b] = {
+ final override def map[b](f: A => b): Array[b] = {
val len = length
val result = new Array[b](len)
var i = 0
@@ -86,7 +86,7 @@ abstract class BoxedArray extends Array.Array0[Any] {
result
}
- final override def flatMap[b](f: Any => Iterable[b]): Array[b] = {
+ final override def flatMap[b](f: A => Iterable[b]): Array[b] = {
val buf = new ArrayBuffer[b]
val len = length
var i = 0
@@ -97,11 +97,11 @@ abstract class BoxedArray extends Array.Array0[Any] {
buf.toArray
}
- final override def ++[b >: Any](that: Iterable[b]): Array[b] = super.++(that).toArray
+ final override def ++[b >: A](that: Iterable[b]): Array[b] = super.++(that).toArray
- final def zip[b](that: Array[b]): Array[(Any,b)] = {
+ final def zip[b](that: Array[b]): Array[(A,b)] = {
val len = this.length min that.length
- val result = new Array[(Any,b)](len)
+ val result = new Array[(A,b)](len)
var i = 0
while (i < len) {
result(i) = (this(i), that(i))
@@ -110,9 +110,9 @@ abstract class BoxedArray extends Array.Array0[Any] {
result
}
- final def zipWithIndex: Array[(Any,Int)] = {
+ final def zipWithIndex: Array[(A,Int)] = {
val len = length
- val result = new Array[(Any,Int)](len)
+ val result = new Array[(A,Int)](len)
var i = 0
while (i < len) {
result(i) = (this(i), i)
@@ -148,7 +148,7 @@ abstract class BoxedArray extends Array.Array0[Any] {
final def deepEquals(that: Any): Boolean = {
def _deepEquals(x1: Any, x2: Any) = (x1, x2) match {
- case (a1: BoxedArray, a2: BoxedArray) =>
+ case (a1: BoxedArray[_], a2: BoxedArray[_]) =>
_sameElements(a1, a2)
case (a1: AnyRef, a2: AnyRef)
if ScalaRunTime.isArray(a1) && ScalaRunTime.isArray(a2) =>
@@ -156,7 +156,7 @@ abstract class BoxedArray extends Array.Array0[Any] {
case _ =>
x1.equals(x2)
}
- def _sameElements(a1: BoxedArray, a2: BoxedArray): Boolean = {
+ def _sameElements(a1: BoxedArray[_], a2: BoxedArray[_]): Boolean = {
val it1 = a1.elements
val it2 = a2.elements
var res = true
@@ -165,7 +165,7 @@ abstract class BoxedArray extends Array.Array0[Any] {
!it1.hasNext && !it2.hasNext && res
}
that match {
- case a: BoxedArray =>
+ case a: BoxedArray[_] =>
_sameElements(this, a)
case a: AnyRef if ScalaRunTime.isArray(a) =>
_sameElements(this, ScalaRunTime.boxArray(a))
@@ -175,13 +175,13 @@ abstract class BoxedArray extends Array.Array0[Any] {
}
override final def stringPrefix: String = "Array"
- protected def newArray(length : Int, elements : Iterator[Any]) : BoxedArray
- override def projection : scala.Array.Projection[Any] = new scala.Array.Projection[Any] {
- def update(idx : Int, what : Any) : Unit = BoxedArray.this.update(idx, what)
+ protected def newArray(length : Int, elements : Iterator[A]) : BoxedArray[A]
+ override def projection : scala.Array.Projection[A] = new scala.Array.Projection[A] {
+ def update(idx : Int, what : A) : Unit = BoxedArray.this.update(idx, what)
def length = BoxedArray.this.length
def apply(idx : Int) = BoxedArray.this.apply(idx)
override def stringPrefix = "ArrayP"
- protected def newArray[B >: Any](length : Int, elements : Iterator[Any]) =
+ protected def newArray[B >: A](length : Int, elements : Iterator[A]) =
BoxedArray.this.newArray(length, elements).asInstanceOf[Array[B]]
}
}
diff --git a/src/library/scala/runtime/BoxedBooleanArray.scala b/src/library/scala/runtime/BoxedBooleanArray.scala
index 9b8182a4e2..bad611d3bd 100644
--- a/src/library/scala/runtime/BoxedBooleanArray.scala
+++ b/src/library/scala/runtime/BoxedBooleanArray.scala
@@ -15,14 +15,14 @@ package scala.runtime
import Predef._
@serializable
-final class BoxedBooleanArray(val value: Array[Boolean]) extends BoxedArray {
+final class BoxedBooleanArray(val value: Array[Boolean]) extends BoxedArray[Boolean] {
def length: Int = value.length
- def apply(index: Int): Any = Boolean.box(value(index))
+ def apply(index: Int): Boolean = value(index)
- def update(index: Int, elem: Any) {
- value(index) = Boolean.unbox(elem.asInstanceOf[AnyRef])
+ def update(index: Int, elem: Boolean) {
+ value(index) = elem
}
def unbox(elemTag: String): AnyRef = value
@@ -40,7 +40,7 @@ final class BoxedBooleanArray(val value: Array[Boolean]) extends BoxedArray {
result
}
- final override def filter(p: Any => Boolean): BoxedArray = {
+ final override def filter(p: Boolean => Boolean): BoxedArray[Boolean] = {
val include = new Array[Boolean](value.length)
var len = 0
var i = 0
@@ -57,7 +57,7 @@ final class BoxedBooleanArray(val value: Array[Boolean]) extends BoxedArray {
}
new BoxedBooleanArray(result)
}
- override protected def newArray(length : Int, elements : Iterator[Any]) = {
+ override protected def newArray(length : Int, elements : Iterator[Boolean]) = {
val result = new Array[Boolean](length)
elements.map(_.asInstanceOf[Boolean]).copyToArray(result, 0)
new BoxedBooleanArray(result)
diff --git a/src/library/scala/runtime/BoxedByteArray.scala b/src/library/scala/runtime/BoxedByteArray.scala
index cbe6e94e69..0c63acada8 100644
--- a/src/library/scala/runtime/BoxedByteArray.scala
+++ b/src/library/scala/runtime/BoxedByteArray.scala
@@ -15,14 +15,14 @@ package scala.runtime
import Predef._
@serializable
-final class BoxedByteArray(val value: Array[Byte]) extends BoxedArray {
+final class BoxedByteArray(val value: Array[Byte]) extends BoxedArray[Byte] {
def length: Int = value.length
- def apply(index: Int): Any = Byte.box(value(index))
+ def apply(index: Int): Byte = value(index)
- def update(index: Int, elem: Any) {
- value(index) = Byte.unbox(elem.asInstanceOf[AnyRef])
+ def update(index: Int, elem: Byte) {
+ value(index) = elem
}
def unbox(elemTag: String): AnyRef = value
@@ -32,7 +32,7 @@ final class BoxedByteArray(val value: Array[Byte]) extends BoxedArray {
value == other ||
other.isInstanceOf[BoxedByteArray] && value == other.asInstanceOf[BoxedByteArray].value
- override def hashCode(): Int = value.hashCode();
+ override def hashCode(): Int = value.hashCode()
def subArray(start: Int, end: Int): Array[Byte] = {
val result = new Array[Byte](end - start)
@@ -40,7 +40,7 @@ final class BoxedByteArray(val value: Array[Byte]) extends BoxedArray {
result
}
- final override def filter(p: Any => Boolean): BoxedArray = {
+ final override def filter(p: Byte => Boolean): BoxedArray[Byte] = {
val include = new Array[Boolean](value.length)
var len = 0
var i = 0
@@ -57,9 +57,11 @@ final class BoxedByteArray(val value: Array[Byte]) extends BoxedArray {
}
new BoxedByteArray(result)
}
- override protected def newArray(length : Int, elements : Iterator[Any]) = {
+ override protected def newArray(length : Int, elements : Iterator[Byte]) = {
val result = new Array[Byte](length)
elements.map(_.asInstanceOf[Byte]).copyToArray(result, 0)
new BoxedByteArray(result)
}
+
+
}
diff --git a/src/library/scala/runtime/BoxedCharArray.scala b/src/library/scala/runtime/BoxedCharArray.scala
index af62aae4d2..54a90fbee3 100644
--- a/src/library/scala/runtime/BoxedCharArray.scala
+++ b/src/library/scala/runtime/BoxedCharArray.scala
@@ -15,25 +15,24 @@ package scala.runtime
import Predef._
@serializable
-final class BoxedCharArray(val value: Array[Char]) extends BoxedArray {
+final class BoxedCharArray(val value: Array[Char]) extends BoxedArray[Char] {
def length: Int = value.length
- def apply(index: Int): Any = Char.box(value(index))
+ def apply(index: Int): Char = value(index)
- def update(index: Int, elem: Any) {
- value(index) = Char.unbox(elem.asInstanceOf[AnyRef])
+ def update(index: Int, elem: Char) {
+ value(index) = elem
}
def unbox(elemTag: String): AnyRef = value
def unbox(elemClass: Class[_]): AnyRef = value
- override def equals(other: Any) = (
+ override def equals(other: Any) =
value == other ||
other.isInstanceOf[BoxedCharArray] && value == other.asInstanceOf[BoxedCharArray].value
- );
- override def hashCode(): Int = value.hashCode();
+ override def hashCode(): Int = value.hashCode()
def subArray(start: Int, end: Int): Array[Char] = {
val result = new Array[Char](end - start)
@@ -41,7 +40,7 @@ final class BoxedCharArray(val value: Array[Char]) extends BoxedArray {
result
}
- final override def filter(p: Any => Boolean): BoxedArray = {
+ final override def filter(p: Char => Boolean): BoxedArray[Char] = {
val include = new Array[Boolean](value.length)
var len = 0
var i = 0
@@ -58,9 +57,11 @@ final class BoxedCharArray(val value: Array[Char]) extends BoxedArray {
}
new BoxedCharArray(result)
}
- override protected def newArray(length : Int, elements : Iterator[Any]) = {
+ override protected def newArray(length : Int, elements : Iterator[Char]) = {
val result = new Array[Char](length)
elements.map(_.asInstanceOf[Char]).copyToArray(result, 0)
new BoxedCharArray(result)
}
+
+
}
diff --git a/src/library/scala/runtime/BoxedDoubleArray.scala b/src/library/scala/runtime/BoxedDoubleArray.scala
index 0dab432728..fdaec061e9 100644
--- a/src/library/scala/runtime/BoxedDoubleArray.scala
+++ b/src/library/scala/runtime/BoxedDoubleArray.scala
@@ -15,14 +15,14 @@ package scala.runtime
import Predef._
@serializable
-final class BoxedDoubleArray(val value: Array[Double]) extends BoxedArray {
+final class BoxedDoubleArray(val value: Array[Double]) extends BoxedArray[Double] {
def length: Int = value.length
- def apply(index: Int): Any = Double.box(value(index))
+ def apply(index: Int): Double = value(index)
- def update(index: Int, elem: Any) {
- value(index) = Double.unbox(elem.asInstanceOf[AnyRef])
+ def update(index: Int, elem: Double) {
+ value(index) = elem
}
def unbox(elemTag: String): AnyRef = value
@@ -40,7 +40,7 @@ final class BoxedDoubleArray(val value: Array[Double]) extends BoxedArray {
result
}
- final override def filter(p: Any => Boolean): BoxedArray = {
+ final override def filter(p: Double => Boolean): BoxedArray[Double] = {
val include = new Array[Boolean](value.length)
var len = 0
var i = 0
@@ -57,9 +57,11 @@ final class BoxedDoubleArray(val value: Array[Double]) extends BoxedArray {
}
new BoxedDoubleArray(result)
}
- override protected def newArray(length : Int, elements : Iterator[Any]) = {
+ override protected def newArray(length : Int, elements : Iterator[Double]) = {
val result = new Array[Double](length)
elements.map(_.asInstanceOf[Double]).copyToArray(result, 0)
new BoxedDoubleArray(result)
}
+
+
}
diff --git a/src/library/scala/runtime/BoxedFloatArray.scala b/src/library/scala/runtime/BoxedFloatArray.scala
index b5135b53ee..05b19dd2e9 100644
--- a/src/library/scala/runtime/BoxedFloatArray.scala
+++ b/src/library/scala/runtime/BoxedFloatArray.scala
@@ -15,14 +15,14 @@ package scala.runtime
import Predef._
@serializable
-final class BoxedFloatArray(val value: Array[Float]) extends BoxedArray {
+final class BoxedFloatArray(val value: Array[Float]) extends BoxedArray[Float] {
def length: Int = value.length
- def apply(index: Int): Any = Float.box(value(index))
+ def apply(index: Int): Float = value(index)
- def update(index: Int, elem: Any) {
- value(index) = Float.unbox(elem.asInstanceOf[AnyRef])
+ def update(index: Int, elem: Float) {
+ value(index) = elem
}
def unbox(elemTag: String): AnyRef = value
@@ -40,7 +40,7 @@ final class BoxedFloatArray(val value: Array[Float]) extends BoxedArray {
result
}
- final override def filter(p: Any => Boolean): BoxedArray = {
+ final override def filter(p: Float => Boolean): BoxedArray[Float] = {
val include = new Array[Boolean](value.length)
var len = 0
var i = 0
@@ -57,9 +57,11 @@ final class BoxedFloatArray(val value: Array[Float]) extends BoxedArray {
}
new BoxedFloatArray(result)
}
- override protected def newArray(length : Int, elements : Iterator[Any]) = {
+ override protected def newArray(length : Int, elements : Iterator[Float]) = {
val result = new Array[Float](length)
elements.map(_.asInstanceOf[Float]).copyToArray(result, 0)
new BoxedFloatArray(result)
}
+
+
}
diff --git a/src/library/scala/runtime/BoxedIntArray.scala b/src/library/scala/runtime/BoxedIntArray.scala
index 4ef3eee629..5c062294c3 100644
--- a/src/library/scala/runtime/BoxedIntArray.scala
+++ b/src/library/scala/runtime/BoxedIntArray.scala
@@ -15,14 +15,14 @@ package scala.runtime
import Predef._
@serializable
-final class BoxedIntArray(val value: Array[Int]) extends BoxedArray {
+final class BoxedIntArray(val value: Array[Int]) extends BoxedArray[Int] {
def length: Int = value.length
- def apply(index: Int): Any = Int.box(value(index))
+ def apply(index: Int): Int = value(index)
- def update(index: Int, elem: Any) {
- value(index) = Int.unbox(elem.asInstanceOf[AnyRef])
+ def update(index: Int, elem: Int) {
+ value(index) = elem
}
def unbox(elemTag: String): AnyRef = value
@@ -40,7 +40,7 @@ final class BoxedIntArray(val value: Array[Int]) extends BoxedArray {
result
}
- final override def filter(p: Any => Boolean): BoxedArray = {
+ final override def filter(p: Int => Boolean): BoxedArray[Int] = {
val include = new Array[Boolean](value.length)
var len = 0
var i = 0
@@ -57,7 +57,7 @@ final class BoxedIntArray(val value: Array[Int]) extends BoxedArray {
}
new BoxedIntArray(result)
}
- override protected def newArray(length : Int, elements : Iterator[Any]) = {
+ override protected def newArray(length : Int, elements : Iterator[Int]) = {
val result = new Array[Int](length)
elements.map(_.asInstanceOf[Int]).copyToArray(result, 0)
new BoxedIntArray(result)
diff --git a/src/library/scala/runtime/BoxedLongArray.scala b/src/library/scala/runtime/BoxedLongArray.scala
index 7b0455e7b0..a94e1e9f04 100644
--- a/src/library/scala/runtime/BoxedLongArray.scala
+++ b/src/library/scala/runtime/BoxedLongArray.scala
@@ -15,14 +15,14 @@ package scala.runtime
import Predef._
@serializable
-final class BoxedLongArray(val value: Array[Long]) extends BoxedArray {
+final class BoxedLongArray(val value: Array[Long]) extends BoxedArray[Long] {
def length: Int = value.length
- def apply(index: Int): Any = Long.box(value(index))
+ def apply(index: Int): Long = value(index)
- def update(index: Int, elem: Any) {
- value(index) = Long.unbox(elem.asInstanceOf[AnyRef])
+ def update(index: Int, elem: Long) {
+ value(index) = elem
}
def unbox(elemTag: String): AnyRef = value
@@ -40,7 +40,7 @@ final class BoxedLongArray(val value: Array[Long]) extends BoxedArray {
result
}
- final override def filter(p: Any => Boolean): BoxedArray = {
+ final override def filter(p: Long => Boolean): BoxedArray[Long] = {
val include = new Array[Boolean](value.length)
var len = 0
var i = 0
@@ -57,9 +57,11 @@ final class BoxedLongArray(val value: Array[Long]) extends BoxedArray {
}
new BoxedLongArray(result)
}
- override protected def newArray(length : Int, elements : Iterator[Any]) = {
+ override protected def newArray(length : Int, elements : Iterator[Long]) = {
val result = new Array[Long](length)
elements.map(_.asInstanceOf[Long]).copyToArray(result, 0)
new BoxedLongArray(result)
}
+
+
}
diff --git a/src/library/scala/runtime/BoxedObjectArray.scala b/src/library/scala/runtime/BoxedObjectArray.scala
index 84cbfbe49f..4146590be4 100644
--- a/src/library/scala/runtime/BoxedObjectArray.scala
+++ b/src/library/scala/runtime/BoxedObjectArray.scala
@@ -16,14 +16,14 @@ import Predef._
import compat.Platform.createArray
@serializable
-final class BoxedObjectArray(val value: Array[AnyRef]) extends BoxedArray {
+final class BoxedObjectArray[A <: AnyRef](val value: Array[AnyRef]) extends BoxedArray[A] {
def length: Int = value.length
- def apply(index: Int): Any = value(index)
+ def apply(index: Int): A = value(index).asInstanceOf[A]
- def update(index: Int, elem: Any) {
- value(index) = elem.asInstanceOf[AnyRef]
+ def update(index: Int, elem: A) {
+ value(index) = elem
}
def unbox(elemTag: String): AnyRef = value
@@ -31,7 +31,7 @@ final class BoxedObjectArray(val value: Array[AnyRef]) extends BoxedArray {
override def equals(other: Any): Boolean =
value == other ||
- other.isInstanceOf[BoxedObjectArray] && value == other.asInstanceOf[BoxedObjectArray].value
+ other.isInstanceOf[BoxedObjectArray[_]] && value == other.asInstanceOf[BoxedObjectArray[_]].value
override def hashCode(): Int = value.hashCode()
@@ -45,12 +45,12 @@ final class BoxedObjectArray(val value: Array[AnyRef]) extends BoxedArray {
result
}
- final override def filter(p: Any => Boolean): BoxedArray = {
+ final override def filter(p: A => Boolean): BoxedArray[A] = {
val include = new Array[Boolean](value.length)
var len = 0
var i = 0
while (i < value.length) {
- if (p(value(i))) { include(i) = true; len += 1 }
+ if (p(value(i).asInstanceOf[A])) { include(i) = true; len += 1 }
i += 1
}
val result = create(len)
@@ -60,13 +60,13 @@ final class BoxedObjectArray(val value: Array[AnyRef]) extends BoxedArray {
if (include(i)) { result(len) = value(i); len += 1 }
i += 1
}
- new BoxedObjectArray(result)
+ new BoxedObjectArray[A](result)
}
- override protected def newArray(length: Int, elements: Iterator[Any]) = {
+ override protected def newArray(length: Int, elements: Iterator[A]) = {
val result = create(length)
- elements.map(_.asInstanceOf[AnyRef]).copyToArray(result, 0)
- new BoxedObjectArray(result)
+ elements.map(_.asInstanceOf[A]).copyToArray(result, 0)
+ new BoxedObjectArray[A](result)
}
}
diff --git a/src/library/scala/runtime/BoxedShortArray.scala b/src/library/scala/runtime/BoxedShortArray.scala
index 41baabbfe0..30a879d26d 100644
--- a/src/library/scala/runtime/BoxedShortArray.scala
+++ b/src/library/scala/runtime/BoxedShortArray.scala
@@ -15,14 +15,14 @@ package scala.runtime
import Predef._
@serializable
-final class BoxedShortArray(val value: Array[Short]) extends BoxedArray {
+final class BoxedShortArray(val value: Array[Short]) extends BoxedArray[Short] {
def length: Int = value.length
- def apply(index: Int): Any = Short.box(value(index))
+ def apply(index: Int): Short = value(index)
- def update(index: Int, elem: Any) {
- value(index) = Short.unbox(elem.asInstanceOf[AnyRef])
+ def update(index: Int, elem: Short) {
+ value(index) = elem
}
def unbox(elemTag: String): AnyRef = value
@@ -40,7 +40,7 @@ final class BoxedShortArray(val value: Array[Short]) extends BoxedArray {
result
}
- final override def filter(p: Any => Boolean): BoxedArray = {
+ final override def filter(p: Short => Boolean): BoxedArray[Short] = {
val include = new Array[Boolean](value.length)
var len = 0
var i = 0
@@ -57,9 +57,11 @@ final class BoxedShortArray(val value: Array[Short]) extends BoxedArray {
}
new BoxedShortArray(result)
}
- override protected def newArray(length : Int, elements : Iterator[Any]) = {
+ override protected def newArray(length : Int, elements : Iterator[Short]) = {
val result = new Array[Short](length)
elements.map(_.asInstanceOf[Short]).copyToArray(result, 0)
new BoxedShortArray(result)
}
+
+
}
diff --git a/src/library/scala/runtime/RichString.scala b/src/library/scala/runtime/RichString.scala
index 9875e340e7..ef76ff2a2e 100644
--- a/src/library/scala/runtime/RichString.scala
+++ b/src/library/scala/runtime/RichString.scala
@@ -239,7 +239,7 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char
def format(args : Any*) : String = {
val m = classOf[String].getDeclaredMethod("format", classOf[String], classOf[Array[Object]])
m.invoke(null, self,
- args.asInstanceOf[scala.runtime.BoxedObjectArray].
+ args.asInstanceOf[scala.runtime.BoxedObjectArray[_]].
unbox(args.getClass).asInstanceOf[Array[Object]]).asInstanceOf[String]
}
}
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala
index e7ebe8659e..02639ba969 100644
--- a/src/library/scala/runtime/ScalaRunTime.scala
+++ b/src/library/scala/runtime/ScalaRunTime.scala
@@ -28,7 +28,7 @@ object ScalaRunTime {
val DoubleTag = ".Double"
val BooleanTag = ".Boolean"
- def isArray(x: AnyRef): Boolean = (x != null && x.getClass.isArray) || (x != null && x.isInstanceOf[BoxedArray])
+ def isArray(x: AnyRef): Boolean = (x != null && x.getClass.isArray) || (x != null && x.isInstanceOf[BoxedArray[_]])
def isValueTag(tag: String) = tag.charAt(0) == '.'
def isValueClass(clazz: Class[_]) = clazz.isPrimitive()
@@ -127,13 +127,13 @@ object ScalaRunTime {
def Seq[a](xs: a*): Seq[a] = null // interpreted specially by new backend.
- def arrayValue(x: BoxedArray, elemTag: String): AnyRef =
+ def arrayValue[A](x: BoxedArray[A], elemTag: String): AnyRef =
if (x eq null) null else x.unbox(elemTag)
- def arrayValue(x: BoxedArray, elemClass: Class[_]): AnyRef =
+ def arrayValue[A](x: BoxedArray[A], elemClass: Class[_]): AnyRef =
if (x eq null) null else x.unbox(elemClass)
- def boxArray(value: AnyRef): BoxedArray = value match {
+ def boxArray(value: AnyRef): BoxedArray[_] = value match {
case x: Array[Byte] => new BoxedByteArray(x)
case x: Array[Short] => new BoxedShortArray(x)
case x: Array[Char] => new BoxedCharArray(x)
@@ -143,7 +143,7 @@ object ScalaRunTime {
case x: Array[Double] => new BoxedDoubleArray(x)
case x: Array[Boolean] => new BoxedBooleanArray(x)
case x: Array[AnyRef] => new BoxedObjectArray(x)
- case x: BoxedArray => x
+ case x: BoxedArray[_] => x
}
/** Given any Scala value, convert it to a String.