From 0f0144c74088e396fc1440166bed5a7c6d5f44f4 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 23 Apr 2012 16:04:56 +0200 Subject: migrates stdlib and compiler to tags * all usages of ClassManifest and Manifest are replaced with tags * all manifest tests are replaced with tag tests --- .../parallel/benchmarks/arrays/Resetting.scala | 8 +- .../parallel_array/MatrixMultiplication.scala | 26 +- test/disabled/presentation/akka.check | 24 +- .../presentation/akka/src/akka/actor/Actor.scala | 4 +- .../akka/src/akka/actor/ActorRef.scala | 16 +- .../akka/src/akka/actor/ActorRegistry.scala | 30 +- .../akka/src/akka/event/EventHandler.scala | 4 +- .../src/akka/remoteinterface/RemoteInterface.scala | 4 +- .../presentation/akka/src/akka/util/Helpers.scala | 2 +- test/disabled/presentation/simple-tests.check | 2 +- test/files/jvm/manifests-new.check | 58 ++ test/files/jvm/manifests-new.scala | 109 ++++ test/files/jvm/manifests.check | 56 -- test/files/jvm/manifests.scala | 112 ---- test/files/jvm/serialization-new.check | 313 ++++++++++ test/files/jvm/serialization-new.scala | 651 +++++++++++++++++++++ test/files/jvm/serialization.check | 313 ---------- test/files/jvm/serialization.scala | 651 --------------------- test/files/neg/t2386.check | 4 - test/files/neg/t2386.scala | 3 - test/files/neg/t3692-new.check | 4 + test/files/neg/t3692-new.flags | 1 + test/files/neg/t3692-new.scala | 19 + test/files/neg/t3692.check | 11 - test/files/neg/t3692.flags | 1 - test/files/neg/t3692.scala | 19 - test/files/neg/t5452-new.check | 8 + test/files/neg/t5452-new.scala | 29 + test/files/neg/t5452.check | 8 - test/files/neg/t5452.scala | 29 - test/files/pos/contextbounds-implicits-new.scala | 8 + test/files/pos/contextbounds-implicits.scala | 8 - test/files/pos/implicits-new.scala | 89 +++ test/files/pos/implicits.scala | 89 --- test/files/pos/manifest1-new.scala | 21 + test/files/pos/manifest1.scala | 21 - test/files/pos/nothing_manifest_disambig-new.scala | 10 + test/files/pos/nothing_manifest_disambig.scala | 10 - test/files/pos/spec-constr-new.scala | 7 + test/files/pos/spec-constr.scala | 7 - test/files/pos/spec-doubledef-new.scala | 28 + test/files/pos/spec-doubledef.scala | 28 - test/files/pos/spec-fields-new.scala | 10 + test/files/pos/spec-fields.scala | 10 - test/files/pos/spec-params-new.scala | 32 + test/files/pos/spec-params.scala | 32 - test/files/pos/spec-sparsearray-new.scala | 24 + test/files/pos/spec-sparsearray.scala | 24 - test/files/pos/t1381-new.scala | 31 + test/files/pos/t1381.scala | 31 - test/files/pos/t2795-new.scala | 17 + test/files/pos/t2795.scala | 17 - test/files/pos/t3363-new.scala | 18 + test/files/pos/t3363.scala | 18 - test/files/pos/t3498-new.scala | 15 + test/files/pos/t3498.scala | 15 - test/files/presentation/ide-bug-1000531.check | 2 +- test/files/run/arrayclone-new.scala | 106 ++++ test/files/run/arrayclone.scala | 106 ---- test/files/run/ctries-new/DumbHash.scala | 14 + test/files/run/ctries-new/Wrap.scala | 9 + test/files/run/ctries-new/concmap.scala | 188 ++++++ test/files/run/ctries-new/iterator.scala | 289 +++++++++ test/files/run/ctries-new/lnode.scala | 61 ++ test/files/run/ctries-new/main.scala | 45 ++ test/files/run/ctries-new/snapshot.scala | 267 +++++++++ test/files/run/ctries/DumbHash.scala | 14 - test/files/run/ctries/Wrap.scala | 9 - test/files/run/ctries/concmap.scala | 188 ------ test/files/run/ctries/iterator.scala | 289 --------- test/files/run/ctries/lnode.scala | 61 -- test/files/run/ctries/main.scala | 45 -- test/files/run/ctries/snapshot.scala | 267 --------- test/files/run/existentials3-new.check | 24 + test/files/run/existentials3-new.scala | 78 +++ test/files/run/existentials3.check | 24 - test/files/run/existentials3.scala | 79 --- test/files/run/getClassTest-new.check | 18 + test/files/run/getClassTest-new.scala | 66 +++ test/files/run/getClassTest.check | 18 - test/files/run/getClassTest.scala | 66 --- test/files/run/manifests-new.scala | 147 +++++ test/files/run/manifests.scala | 149 ----- test/files/run/patmat_unapp_abstype-new.check | 4 + test/files/run/patmat_unapp_abstype-new.flags | 1 + test/files/run/patmat_unapp_abstype-new.scala | 83 +++ test/files/run/patmat_unapp_abstype.check | 4 - test/files/run/patmat_unapp_abstype.flags | 1 - test/files/run/patmat_unapp_abstype.scala | 83 --- test/files/run/primitive-sigs-2-new.check | 7 + test/files/run/primitive-sigs-2-new.scala | 31 + test/files/run/primitive-sigs-2.check | 7 - test/files/run/primitive-sigs-2.scala | 39 -- test/files/run/reflection-implClass-new.scala | 38 ++ test/files/run/reflection-implClass.scala | 38 -- test/files/run/reify_implicits-new.check | 1 + test/files/run/reify_implicits-new.scala | 14 + test/files/run/reify_implicits.check | 1 - test/files/run/reify_implicits.scala | 14 - test/files/run/repl-power.check | 64 +- test/files/run/repl-power.scala | 3 +- test/files/run/t0421-new.check | 3 + test/files/run/t0421-new.scala | 30 + test/files/run/t0421.check | 3 - test/files/run/t0421.scala | 30 - test/files/run/t0677-new.scala | 8 + test/files/run/t0677.scala | 8 - test/files/run/t1195-new.check | 6 + test/files/run/t1195-new.scala | 26 + test/files/run/t1195.check | 6 - test/files/run/t1195.scala | 26 - test/files/run/t2236-new.scala | 17 + test/files/run/t2236.scala | 17 - test/files/run/t2386-new.check | 2 + test/files/run/t2386-new.scala | 5 + test/files/run/t3507-new.check | 1 + test/files/run/t3507-new.scala | 15 + test/files/run/t3507.check | 1 - test/files/run/t3507.scala | 15 - test/files/run/t3758.check | 6 - test/files/run/t3758.scala | 10 - test/files/run/t4110-new.check | 2 + test/files/run/t4110-new.scala | 11 + test/files/run/t4110.check | 2 - test/files/run/t4110.scala | 11 - test/files/scalacheck/array-new.scala | 36 ++ test/files/scalacheck/array.scala | 37 -- test/files/specialized/spec-matrix-new.check | 2 + test/files/specialized/spec-matrix-new.scala | 80 +++ test/files/specialized/spec-matrix.check | 2 - test/files/specialized/spec-matrix.scala | 80 --- test/pending/pos/inference.scala | 20 +- test/pending/shootout/meteor.scala | 64 +- test/scaladoc/resources/implicits-base-res.scala | 3 +- 134 files changed, 3375 insertions(+), 3411 deletions(-) create mode 100644 test/files/jvm/manifests-new.check create mode 100644 test/files/jvm/manifests-new.scala delete mode 100644 test/files/jvm/manifests.check delete mode 100644 test/files/jvm/manifests.scala create mode 100644 test/files/jvm/serialization-new.check create mode 100644 test/files/jvm/serialization-new.scala delete mode 100644 test/files/jvm/serialization.check delete mode 100644 test/files/jvm/serialization.scala delete mode 100644 test/files/neg/t2386.check delete mode 100644 test/files/neg/t2386.scala create mode 100644 test/files/neg/t3692-new.check create mode 100644 test/files/neg/t3692-new.flags create mode 100644 test/files/neg/t3692-new.scala delete mode 100644 test/files/neg/t3692.check delete mode 100644 test/files/neg/t3692.flags delete mode 100644 test/files/neg/t3692.scala create mode 100644 test/files/neg/t5452-new.check create mode 100644 test/files/neg/t5452-new.scala delete mode 100644 test/files/neg/t5452.check delete mode 100644 test/files/neg/t5452.scala create mode 100644 test/files/pos/contextbounds-implicits-new.scala delete mode 100644 test/files/pos/contextbounds-implicits.scala create mode 100644 test/files/pos/implicits-new.scala delete mode 100644 test/files/pos/implicits.scala create mode 100644 test/files/pos/manifest1-new.scala delete mode 100644 test/files/pos/manifest1.scala create mode 100644 test/files/pos/nothing_manifest_disambig-new.scala delete mode 100644 test/files/pos/nothing_manifest_disambig.scala create mode 100644 test/files/pos/spec-constr-new.scala delete mode 100644 test/files/pos/spec-constr.scala create mode 100644 test/files/pos/spec-doubledef-new.scala delete mode 100644 test/files/pos/spec-doubledef.scala create mode 100644 test/files/pos/spec-fields-new.scala delete mode 100644 test/files/pos/spec-fields.scala create mode 100644 test/files/pos/spec-params-new.scala delete mode 100644 test/files/pos/spec-params.scala create mode 100644 test/files/pos/spec-sparsearray-new.scala delete mode 100644 test/files/pos/spec-sparsearray.scala create mode 100644 test/files/pos/t1381-new.scala delete mode 100644 test/files/pos/t1381.scala create mode 100644 test/files/pos/t2795-new.scala delete mode 100644 test/files/pos/t2795.scala create mode 100644 test/files/pos/t3363-new.scala delete mode 100755 test/files/pos/t3363.scala create mode 100644 test/files/pos/t3498-new.scala delete mode 100644 test/files/pos/t3498.scala create mode 100644 test/files/run/arrayclone-new.scala delete mode 100644 test/files/run/arrayclone.scala create mode 100644 test/files/run/ctries-new/DumbHash.scala create mode 100644 test/files/run/ctries-new/Wrap.scala create mode 100644 test/files/run/ctries-new/concmap.scala create mode 100644 test/files/run/ctries-new/iterator.scala create mode 100644 test/files/run/ctries-new/lnode.scala create mode 100644 test/files/run/ctries-new/main.scala create mode 100644 test/files/run/ctries-new/snapshot.scala delete mode 100644 test/files/run/ctries/DumbHash.scala delete mode 100644 test/files/run/ctries/Wrap.scala delete mode 100644 test/files/run/ctries/concmap.scala delete mode 100644 test/files/run/ctries/iterator.scala delete mode 100644 test/files/run/ctries/lnode.scala delete mode 100644 test/files/run/ctries/main.scala delete mode 100644 test/files/run/ctries/snapshot.scala create mode 100644 test/files/run/existentials3-new.check create mode 100644 test/files/run/existentials3-new.scala delete mode 100644 test/files/run/existentials3.check delete mode 100644 test/files/run/existentials3.scala create mode 100644 test/files/run/getClassTest-new.check create mode 100644 test/files/run/getClassTest-new.scala delete mode 100644 test/files/run/getClassTest.check delete mode 100644 test/files/run/getClassTest.scala create mode 100644 test/files/run/manifests-new.scala delete mode 100644 test/files/run/manifests.scala create mode 100644 test/files/run/patmat_unapp_abstype-new.check create mode 100644 test/files/run/patmat_unapp_abstype-new.flags create mode 100644 test/files/run/patmat_unapp_abstype-new.scala delete mode 100644 test/files/run/patmat_unapp_abstype.check delete mode 100644 test/files/run/patmat_unapp_abstype.flags delete mode 100644 test/files/run/patmat_unapp_abstype.scala create mode 100644 test/files/run/primitive-sigs-2-new.check create mode 100644 test/files/run/primitive-sigs-2-new.scala delete mode 100644 test/files/run/primitive-sigs-2.check delete mode 100644 test/files/run/primitive-sigs-2.scala create mode 100644 test/files/run/reflection-implClass-new.scala delete mode 100644 test/files/run/reflection-implClass.scala create mode 100644 test/files/run/reify_implicits-new.check create mode 100644 test/files/run/reify_implicits-new.scala delete mode 100644 test/files/run/reify_implicits.check delete mode 100644 test/files/run/reify_implicits.scala create mode 100644 test/files/run/t0421-new.check create mode 100644 test/files/run/t0421-new.scala delete mode 100644 test/files/run/t0421.check delete mode 100644 test/files/run/t0421.scala create mode 100644 test/files/run/t0677-new.scala delete mode 100644 test/files/run/t0677.scala create mode 100644 test/files/run/t1195-new.check create mode 100644 test/files/run/t1195-new.scala delete mode 100644 test/files/run/t1195.check delete mode 100644 test/files/run/t1195.scala create mode 100644 test/files/run/t2236-new.scala delete mode 100755 test/files/run/t2236.scala create mode 100644 test/files/run/t2386-new.check create mode 100644 test/files/run/t2386-new.scala create mode 100644 test/files/run/t3507-new.check create mode 100644 test/files/run/t3507-new.scala delete mode 100644 test/files/run/t3507.check delete mode 100644 test/files/run/t3507.scala delete mode 100644 test/files/run/t3758.check delete mode 100644 test/files/run/t3758.scala create mode 100644 test/files/run/t4110-new.check create mode 100644 test/files/run/t4110-new.scala delete mode 100644 test/files/run/t4110.check delete mode 100644 test/files/run/t4110.scala create mode 100644 test/files/scalacheck/array-new.scala delete mode 100644 test/files/scalacheck/array.scala create mode 100644 test/files/specialized/spec-matrix-new.check create mode 100644 test/files/specialized/spec-matrix-new.scala delete mode 100644 test/files/specialized/spec-matrix.check delete mode 100644 test/files/specialized/spec-matrix.scala (limited to 'test') diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Resetting.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Resetting.scala index e6feb59fcd..22d2107f62 100644 --- a/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Resetting.scala +++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Resetting.scala @@ -4,19 +4,19 @@ package scala.collection.parallel.benchmarks.arrays import scala.collection.parallel.benchmarks._ -abstract class Resetting[T: Manifest](elemcreate: Int => T, sz: Int, p: Int, what: String) +abstract class Resetting[T: ClassTag](elemcreate: Int => T, sz: Int, p: Int, what: String) extends Bench { val size = sz val parallelism = p val runWhat = what - + var anyarray: Array[Any] = null var castarray: AnyRef = null var gencastarray: Array[T] = null var manifarray: Array[T] = null - + reset - + def reset = what match { case "any" => anyarray = new Array[Any](sz) diff --git a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MatrixMultiplication.scala b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MatrixMultiplication.scala index 5f902ff483..6d5b189c3a 100644 --- a/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MatrixMultiplication.scala +++ b/test/benchmarks/src/scala/collection/parallel/benchmarks/parallel_array/MatrixMultiplication.scala @@ -16,54 +16,54 @@ class MatrixMultiplication(sz: Int, p: Int, what: String) extends Resettable(sz, p, what, new Cont(_), new Array[Any](_), classOf[Cont]) { def companion = MatrixMultiplication collection.parallel.tasksupport.environment = forkjoinpool - + val a = Matrix.unit[Int](sz) val b = Matrix.unit[Int](sz) var c = new Matrix[Int](sz) - + def runpar = c = a * b //{ c.assignProduct(a, b) } //; println("--------"); c.output } def runseq = throw new UnsupportedOperationException def comparisonMap = collection.Map() - - class Matrix[T](n: Int)(implicit num: Numeric[T], man: Manifest[T]) { + + class Matrix[T](n: Int)(implicit num: Numeric[T], tag: ClassTag[T]) { val array = new Array[T](n * n) - + def apply(y: Int, x: Int) = array(y * n + x) - + def update(y: Int, x: Int, elem: T) = array(y * n + x) = elem - + def *(b: Matrix[T]) = { val m = new Matrix[T](n) m.assignProduct(this, b) m } - + def assignProduct(a: Matrix[T], b: Matrix[T]) = { val range = ParRange(0, n * n, 1, false) for (i <- range) this(i / n, i % n) = calcProduct(a, b, i / n, i % n); } - + private def calcProduct(a: Matrix[T], b: Matrix[T], y: Int, x: Int): T = { import num._ var sum = zero for (i <- 0 until n) sum += a(y, i) * b(i, x) sum } - + def output = for (y <- 0 until n) { for (x <- 0 until n) print(this(y, x)) println } } - + object Matrix { - def unit[T](n: Int)(implicit num: Numeric[T], man: Manifest[T]) = { + def unit[T](n: Int)(implicit num: Numeric[T], tag: ClassTag[T]) = { val m = new Matrix[T](n) for (i <- 0 until n) m(i, i) = num.one m } } - + } diff --git a/test/disabled/presentation/akka.check b/test/disabled/presentation/akka.check index 9cd20ffb1c..5105d85a00 100644 --- a/test/disabled/presentation/akka.check +++ b/test/disabled/presentation/akka.check @@ -153,11 +153,11 @@ retrieved 131 members `method spawn(clazz: Class[_ <: akka.actor.Actor])akka.actor.ActorRef` `method spawnLink(clazz: Class[_ <: akka.actor.Actor])akka.actor.ActorRef` `method spawnLinkRemote(clazz: Class[_ <: akka.actor.Actor], hostname: String, port: Int, timeout: Long)akka.actor.ActorRef` -`method spawnLinkRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$4: Manifest[T])akka.actor.ActorRef` -`method spawnLink[T <: akka.actor.Actor](implicit evidence$3: Manifest[T])akka.actor.ActorRef` +`method spawnLinkRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$4: ClassTag[T])akka.actor.ActorRef` +`method spawnLink[T <: akka.actor.Actor](implicit evidence$3: ClassTag[T])akka.actor.ActorRef` `method spawnRemote(clazz: Class[_ <: akka.actor.Actor], hostname: String, port: Int, timeout: Long)akka.actor.ActorRef` -`method spawnRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$2: Manifest[T])akka.actor.ActorRef` -`method spawn[T <: akka.actor.Actor](implicit evidence$1: Manifest[T])akka.actor.ActorRef` +`method spawnRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$2: ClassTag[T])akka.actor.ActorRef` +`method spawn[T <: akka.actor.Actor](implicit evidence$1: ClassTag[T])akka.actor.ActorRef` `method start()akka.actor.ActorRef` `method startLink(actorRef: akka.actor.ActorRef)Unit` `method stop()Unit` @@ -286,11 +286,11 @@ retrieved 131 members `method spawn(clazz: Class[_ <: akka.actor.Actor])akka.actor.ActorRef` `method spawnLink(clazz: Class[_ <: akka.actor.Actor])akka.actor.ActorRef` `method spawnLinkRemote(clazz: Class[_ <: akka.actor.Actor], hostname: String, port: Int, timeout: Long)akka.actor.ActorRef` -`method spawnLinkRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$4: Manifest[T])akka.actor.ActorRef` -`method spawnLink[T <: akka.actor.Actor](implicit evidence$3: Manifest[T])akka.actor.ActorRef` +`method spawnLinkRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$4: ClassTag[T])akka.actor.ActorRef` +`method spawnLink[T <: akka.actor.Actor](implicit evidence$3: ClassTag[T])akka.actor.ActorRef` `method spawnRemote(clazz: Class[_ <: akka.actor.Actor], hostname: String, port: Int, timeout: Long)akka.actor.ActorRef` -`method spawnRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$2: Manifest[T])akka.actor.ActorRef` -`method spawn[T <: akka.actor.Actor](implicit evidence$1: Manifest[T])akka.actor.ActorRef` +`method spawnRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$2: ClassTag[T])akka.actor.ActorRef` +`method spawn[T <: akka.actor.Actor](implicit evidence$1: ClassTag[T])akka.actor.ActorRef` `method start()akka.actor.ActorRef` `method startLink(actorRef: akka.actor.ActorRef)Unit` `method stop()Unit` @@ -419,11 +419,11 @@ retrieved 131 members `method spawn(clazz: Class[_ <: akka.actor.Actor])akka.actor.ActorRef` `method spawnLink(clazz: Class[_ <: akka.actor.Actor])akka.actor.ActorRef` `method spawnLinkRemote(clazz: Class[_ <: akka.actor.Actor], hostname: String, port: Int, timeout: Long)akka.actor.ActorRef` -`method spawnLinkRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$4: Manifest[T])akka.actor.ActorRef` -`method spawnLink[T <: akka.actor.Actor](implicit evidence$3: Manifest[T])akka.actor.ActorRef` +`method spawnLinkRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$4: ClassTag[T])akka.actor.ActorRef` +`method spawnLink[T <: akka.actor.Actor](implicit evidence$3: ClassTag[T])akka.actor.ActorRef` `method spawnRemote(clazz: Class[_ <: akka.actor.Actor], hostname: String, port: Int, timeout: Long)akka.actor.ActorRef` -`method spawnRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$2: Manifest[T])akka.actor.ActorRef` -`method spawn[T <: akka.actor.Actor](implicit evidence$1: Manifest[T])akka.actor.ActorRef` +`method spawnRemote[T <: akka.actor.Actor](hostname: String, port: Int, timeout: Long)(implicit evidence$2: ClassTag[T])akka.actor.ActorRef` +`method spawn[T <: akka.actor.Actor](implicit evidence$1: ClassTag[T])akka.actor.ActorRef` `method start()akka.actor.ActorRef` `method startLink(actorRef: akka.actor.ActorRef)Unit` `method stop()Unit` diff --git a/test/disabled/presentation/akka/src/akka/actor/Actor.scala b/test/disabled/presentation/akka/src/akka/actor/Actor.scala index b955c4c38b..b9bc51b635 100644 --- a/test/disabled/presentation/akka/src/akka/actor/Actor.scala +++ b/test/disabled/presentation/akka/src/akka/actor/Actor.scala @@ -135,7 +135,7 @@ object Actor extends ListenerManagement { * val actor = actorOf[MyActor].start() * */ - def actorOf[T <: Actor: Manifest]: ActorRef = actorOf(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]]) + def actorOf[T <: Actor: ClassTag]: ActorRef = actorOf(classTag[T].erasure.asInstanceOf[Class[_ <: Actor]]) /** Creates an ActorRef out of the Actor of the specified Class. *
@@ -481,7 +481,7 @@ private[actor] class AnyOptionAsTypedOption(anyOption: Option[Any]) {
   /** Convenience helper to cast the given Option of Any to an Option of the given type. Will swallow a possible
    *  ClassCastException and return None in that case.
    */
-  def asSilently[T: Manifest]: Option[T] = narrowSilently[T](anyOption)
+  def asSilently[T: ClassTag]: Option[T] = narrowSilently[T](anyOption)
 }
 
 /** Marker interface for proxyable actors (such as typed actor).
diff --git a/test/disabled/presentation/akka/src/akka/actor/ActorRef.scala b/test/disabled/presentation/akka/src/akka/actor/ActorRef.scala
index ff67c9468e..da0b63006a 100644
--- a/test/disabled/presentation/akka/src/akka/actor/ActorRef.scala
+++ b/test/disabled/presentation/akka/src/akka/actor/ActorRef.scala
@@ -1406,28 +1406,28 @@ trait ScalaActorRef extends ActorRefShared { ref: ActorRef =>
   /**
    * Atomically create (from actor class) and start an actor.
    */
-  def spawn[T <: Actor: Manifest]: ActorRef =
-    spawn(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]])
+  def spawn[T <: Actor: ClassTag]: ActorRef =
+    spawn(classTag[T].erasure.asInstanceOf[Class[_ <: Actor]])
 
   /**
    * Atomically create (from actor class), start and make an actor remote.
    */
-  def spawnRemote[T <: Actor: Manifest](hostname: String, port: Int, timeout: Long): ActorRef = {
+  def spawnRemote[T <: Actor: ClassTag](hostname: String, port: Int, timeout: Long): ActorRef = {
     ensureRemotingEnabled
-    spawnRemote(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]], hostname, port, timeout)
+    spawnRemote(classTag[T].erasure.asInstanceOf[Class[_ <: Actor]], hostname, port, timeout)
   }
 
   /**
    * Atomically create (from actor class), start and link an actor.
    */
-  def spawnLink[T <: Actor: Manifest]: ActorRef =
-    spawnLink(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]])
+  def spawnLink[T <: Actor: ClassTag]: ActorRef =
+    spawnLink(classTag[T].erasure.asInstanceOf[Class[_ <: Actor]])
 
   /**
    * Atomically create (from actor class), start, link and make an actor remote.
    */
-  def spawnLinkRemote[T <: Actor: Manifest](hostname: String, port: Int, timeout: Long): ActorRef = {
+  def spawnLinkRemote[T <: Actor: ClassTag](hostname: String, port: Int, timeout: Long): ActorRef = {
     ensureRemotingEnabled
-    spawnLinkRemote(manifest[T].erasure.asInstanceOf[Class[_ <: Actor]], hostname, port, timeout)
+    spawnLinkRemote(classTag[T].erasure.asInstanceOf[Class[_ <: Actor]], hostname, port, timeout)
   }
 }
diff --git a/test/disabled/presentation/akka/src/akka/actor/ActorRegistry.scala b/test/disabled/presentation/akka/src/akka/actor/ActorRegistry.scala
index df335dc8b4..5d649fcd36 100644
--- a/test/disabled/presentation/akka/src/akka/actor/ActorRegistry.scala
+++ b/test/disabled/presentation/akka/src/akka/actor/ActorRegistry.scala
@@ -5,7 +5,7 @@
 package akka.actor
 
 import scala.collection.mutable.{ ListBuffer, Map }
-import scala.reflect.Manifest
+import scala.reflect.ArrayTag
 
 import java.util.concurrent.{ ConcurrentSkipListSet, ConcurrentHashMap }
 import java.util.{ Set => JSet }
@@ -74,10 +74,10 @@ final class ActorRegistry private[actor] () extends ListenerManagement {
   }
 
   /**
-   * Finds all actors that are subtypes of the class passed in as the Manifest argument and supporting passed message.
+   * Finds all actors that are subtypes of the class passed in as the ClassTag argument and supporting passed message.
    */
-  def actorsFor[T <: Actor](message: Any)(implicit manifest: Manifest[T]): Array[ActorRef] =
-    filter(a => manifest.erasure.isAssignableFrom(a.actor.getClass) && a.isDefinedAt(message))
+  def actorsFor[T <: Actor](message: Any)(implicit classTag: ClassTag[T]): Array[ActorRef] =
+    filter(a => classTag.erasure.isAssignableFrom(a.actor.getClass) && a.isDefinedAt(message))
 
   /**
    * Finds all actors that satisfy a predicate.
@@ -93,16 +93,16 @@ final class ActorRegistry private[actor] () extends ListenerManagement {
   }
 
   /**
-   * Finds all actors that are subtypes of the class passed in as the Manifest argument.
+   * Finds all actors that are subtypes of the class passed in as the ClassTag argument.
    */
-  def actorsFor[T <: Actor](implicit manifest: Manifest[T]): Array[ActorRef] =
-    actorsFor[T](manifest.erasure.asInstanceOf[Class[T]])
+  def actorsFor[T <: Actor](implicit classTag: ClassTag[T]): Array[ActorRef] =
+    actorsFor[T](classTag.erasure.asInstanceOf[Class[T]])
 
   /**
    * Finds any actor that matches T. Very expensive, traverses ALL alive actors.
    */
-  def actorFor[T <: Actor](implicit manifest: Manifest[T]): Option[ActorRef] =
-    find({ case a: ActorRef if manifest.erasure.isAssignableFrom(a.actor.getClass) => a })
+  def actorFor[T <: Actor](implicit classTag: ClassTag[T]): Option[ActorRef] =
+    find({ case a: ActorRef if classTag.erasure.isAssignableFrom(a.actor.getClass) => a })
 
   /**
    * Finds all actors of type or sub-type specified by the class passed in as the Class argument.
@@ -166,21 +166,21 @@ final class ActorRegistry private[actor] () extends ListenerManagement {
   }
 
   /**
-   * Finds all typed actors that are subtypes of the class passed in as the Manifest argument.
+   * Finds all typed actors that are subtypes of the class passed in as the ClassTag argument.
    */
-  def typedActorsFor[T <: AnyRef](implicit manifest: Manifest[T]): Array[AnyRef] = {
+  def typedActorsFor[T <: AnyRef](implicit classTag: ClassTag[T]): Array[AnyRef] = {
     TypedActorModule.ensureEnabled
-    typedActorsFor[T](manifest.erasure.asInstanceOf[Class[T]])
+    typedActorsFor[T](classTag.erasure.asInstanceOf[Class[T]])
   }
 
   /**
    * Finds any typed actor that matches T.
    */
-  def typedActorFor[T <: AnyRef](implicit manifest: Manifest[T]): Option[AnyRef] = {
+  def typedActorFor[T <: AnyRef](implicit classTag: ClassTag[T]): Option[AnyRef] = {
     TypedActorModule.ensureEnabled
     def predicate(proxy: AnyRef): Boolean = {
       val actorRef = TypedActorModule.typedActorObjectInstance.get.actorFor(proxy)
-      actorRef.isDefined && manifest.erasure.isAssignableFrom(actorRef.get.actor.getClass)
+      actorRef.isDefined && classTag.erasure.isAssignableFrom(actorRef.get.actor.getClass)
     }
     findTypedActor({ case a: Some[AnyRef] if predicate(a.get) => a })
   }
@@ -279,7 +279,7 @@ final class ActorRegistry private[actor] () extends ListenerManagement {
  *
  * @author Viktor Klang
  */
-class Index[K <: AnyRef, V <: AnyRef: Manifest] {
+class Index[K <: AnyRef, V <: AnyRef: ArrayTag] {
   private val Naught = Array[V]() //Nil for Arrays
   private val container = new ConcurrentHashMap[K, JSet[V]]
   private val emptySet = new ConcurrentSkipListSet[V]
diff --git a/test/disabled/presentation/akka/src/akka/event/EventHandler.scala b/test/disabled/presentation/akka/src/akka/event/EventHandler.scala
index f3176b7c21..af2fee6c47 100644
--- a/test/disabled/presentation/akka/src/akka/event/EventHandler.scala
+++ b/test/disabled/presentation/akka/src/akka/event/EventHandler.scala
@@ -115,8 +115,8 @@ object EventHandler extends ListenerManagement {
       notifyListeners(event)
   }
 
-  def notify[T <: Event: ClassManifest](event: => T) {
-    if (level >= levelFor(classManifest[T].erasure.asInstanceOf[Class[_ <: Event]])) notifyListeners(event)
+  def notify[T <: Event: ClassTag](event: => T) {
+    if (level >= levelFor(classTag[T].erasure.asInstanceOf[Class[_ <: Event]])) notifyListeners(event)
   }
 
   def error(cause: Throwable, instance: AnyRef, message: => String) {
diff --git a/test/disabled/presentation/akka/src/akka/remoteinterface/RemoteInterface.scala b/test/disabled/presentation/akka/src/akka/remoteinterface/RemoteInterface.scala
index 0c5da82294..5219c49dcb 100644
--- a/test/disabled/presentation/akka/src/akka/remoteinterface/RemoteInterface.scala
+++ b/test/disabled/presentation/akka/src/akka/remoteinterface/RemoteInterface.scala
@@ -206,8 +206,8 @@ abstract class RemoteSupport extends ListenerManagement with RemoteServerModule
    * 
*/ @deprecated("Will be removed after 1.1", "1.1") - def actorOf[T <: Actor: Manifest](host: String, port: Int): ActorRef = - clientManagedActorOf(() => createActorFromClass(manifest.erasure), host, port) + def actorOf[T <: Actor: ClassTag](host: String, port: Int): ActorRef = + clientManagedActorOf(() => createActorFromClass(classTag[T].erasure), host, port) protected def createActorFromClass(clazz: Class[_]): Actor = { import ReflectiveAccess.{ createInstance, noParams, noArgs } diff --git a/test/disabled/presentation/akka/src/akka/util/Helpers.scala b/test/disabled/presentation/akka/src/akka/util/Helpers.scala index 48477426c9..0ff45408d0 100644 --- a/test/disabled/presentation/akka/src/akka/util/Helpers.scala +++ b/test/disabled/presentation/akka/src/akka/util/Helpers.scala @@ -37,7 +37,7 @@ object Helpers { * Convenience helper to cast the given Option of Any to an Option of the given type. Will swallow a possible * ClassCastException and return None in that case. */ - def narrowSilently[T: Manifest](o: Option[Any]): Option[T] = + def narrowSilently[T: ClassTag](o: Option[Any]): Option[T] = try { narrow(o) } catch { diff --git a/test/disabled/presentation/simple-tests.check b/test/disabled/presentation/simple-tests.check index b90dfce77c..cdb80ed987 100644 --- a/test/disabled/presentation/simple-tests.check +++ b/test/disabled/presentation/simple-tests.check @@ -244,7 +244,7 @@ TypeMember(method disable,(s: Tester.this.settings.Setting)scala.collection.muta TypeMember(value disable,Tester.this.settings.MultiStringSetting,false,true,) TypeMember(value elidebelow,Tester.this.settings.IntSetting,false,true,) TypeMember(method embeddedDefaults,(loader: java.lang.ClassLoader)Unit,true,true,) -TypeMember(method embeddedDefaults,[T](implicit evidence$1: Manifest[T])Unit,true,true,) +TypeMember(method embeddedDefaults,[T](implicit evidence$1: ClassTag[T])Unit,true,true,) TypeMember(value encoding,Tester.this.settings.StringSetting,false,true,) TypeMember(method ensuring,(cond: (scala.tools.nsc.Settings) => Boolean,msg: => Any)scala.tools.nsc.Settings,true,false,method any2Ensuring) TypeMember(method ensuring,(cond: (scala.tools.nsc.Settings) => Boolean)scala.tools.nsc.Settings,true,false,method any2Ensuring) diff --git a/test/files/jvm/manifests-new.check b/test/files/jvm/manifests-new.check new file mode 100644 index 0000000000..9fca856970 --- /dev/null +++ b/test/files/jvm/manifests-new.check @@ -0,0 +1,58 @@ +x=(), t=ConcreteTypeTag[Unit], k=TypeRef, s=class Unit +x=true, t=ConcreteTypeTag[Boolean], k=TypeRef, s=class Boolean +x=a, t=ConcreteTypeTag[Char], k=TypeRef, s=class Char +x=1, t=ConcreteTypeTag[Int], k=TypeRef, s=class Int +x=abc, t=ConcreteTypeTag[String], k=TypeRef, s=class String +x='abc, t=ConcreteTypeTag[Symbol], k=TypeRef, s=class Symbol + +x=List(()), t=ConcreteTypeTag[List[Unit]], k=TypeRef, s=class List +x=List(true), t=ConcreteTypeTag[List[Boolean]], k=TypeRef, s=class List +x=List(1), t=ConcreteTypeTag[List[Int]], k=TypeRef, s=class List +x=List(abc), t=ConcreteTypeTag[List[String]], k=TypeRef, s=class List +x=List('abc), t=ConcreteTypeTag[List[Symbol]], k=TypeRef, s=class List + +x=[Z, t=ConcreteTypeTag[Array[Boolean]], k=TypeRef, s=class Array +x=[C, t=ConcreteTypeTag[Array[Char]], k=TypeRef, s=class Array +x=[I, t=ConcreteTypeTag[Array[Int]], k=TypeRef, s=class Array +x=[Ljava.lang.String;, t=ConcreteTypeTag[Array[String]], k=TypeRef, s=class Array +x=[Lscala.Symbol;, t=ConcreteTypeTag[Array[Symbol]], k=TypeRef, s=class Array + +x=((),()), t=ConcreteTypeTag[(Unit, Unit)], k=TypeRef, s=class Tuple2 +x=(true,false), t=ConcreteTypeTag[(Boolean, Boolean)], k=TypeRef, s=class Tuple2 +x=(1,2), t=ConcreteTypeTag[(Int, Int)], k=TypeRef, s=class Tuple2 +x=(abc,xyz), t=ConcreteTypeTag[(String, String)], k=TypeRef, s=class Tuple2 +x=('abc,'xyz), t=ConcreteTypeTag[(Symbol, Symbol)], k=TypeRef, s=class Tuple2 + +x=Test$, t=ConcreteTypeTag[Test.type], k=TypeRef, s=object Test +x=scala.collection.immutable.List$, t=ConcreteTypeTag[scala.collection.immutable.List.type], k=TypeRef, s=object List + +x=Foo, t=ConcreteTypeTag[Foo[Int]], k=TypeRef, s=class Foo +x=Foo, t=ConcreteTypeTag[Foo[List[Int]]], k=TypeRef, s=class Foo +x=Foo, t=ConcreteTypeTag[Foo[Foo[Int]]], k=TypeRef, s=class Foo +x=Foo, t=ConcreteTypeTag[Foo[List[Foo[Int]]]], k=TypeRef, s=class Foo + +x=Test1$$anon$1, t=ConcreteTypeTag[Bar[String]], k=RefinedType, s= +x=Test1$$anon$2, t=ConcreteTypeTag[Bar[String]], k=RefinedType, s= + +()=() +true=true +a=a +1=1 +'abc='abc + +List(())=List(()) +List(true)=List(true) +List('abc)=List('abc) + +Array()=Array() +Array(true)=Array(true) +Array(a)=Array(a) +Array(1)=Array(1) + +((),())=((),()) +(true,false)=(true,false) + +List(List(1), List(2))=List(List(1), List(2)) + +Array(Array(1), Array(2))=Array(Array(1), Array(2)) + diff --git a/test/files/jvm/manifests-new.scala b/test/files/jvm/manifests-new.scala new file mode 100644 index 0000000000..d02f6ee608 --- /dev/null +++ b/test/files/jvm/manifests-new.scala @@ -0,0 +1,109 @@ +object Test extends App { + Test1 + Test2 +} + +class Foo[T](x: T) +trait Bar[T] { def f: T } + +object Test1 extends TestUtil { + print(()) + print(true) + print('a') + print(1) + print("abc") + print('abc) + println() + + print(List(())) + print(List(true)) + print(List(1)) + print(List("abc")) + print(List('abc)) + println() + + //print(Array(())) //Illegal class name "[V" in class file Test$ + print(Array(true)) + print(Array('a')) + print(Array(1)) + print(Array("abc")) + print(Array('abc)) + println() + + print(((), ())) + print((true, false)) + print((1, 2)) + print(("abc", "xyz")) + print(('abc, 'xyz)) + println() + + print(Test) + print(List) + println() + + print(new Foo(2)) + print(new Foo(List(2))) + print(new Foo(new Foo(2))) + print(new Foo(List(new Foo(2)))) + println() + + print(new Bar[String] { def f = "abc" }); + {print(new Bar[String] { def f = "abc" })} + println() +} + +object Test2 { + import scala.util.Marshal._ + println("()="+load[Unit](dump(()))) + println("true="+load[Boolean](dump(true))) + println("a="+load[Char](dump('a'))) + println("1="+load[Int](dump(1))) + println("'abc="+load[Symbol](dump('abc))) + println() + + println("List(())="+load[List[Unit]](dump(List(())))) + println("List(true)="+load[List[Boolean]](dump(List(true)))) + println("List('abc)="+load[List[Symbol]](dump(List('abc)))) + println() + + def loadArray[T](x: Array[Byte])(implicit t: reflect.ClassTag[Array[T]]) = + load[Array[T]](x)(t).deep.toString + println("Array()="+loadArray[Int](dump(Array(): Array[Int]))) + println("Array(true)="+loadArray[Boolean](dump(Array(true)))) + println("Array(a)="+loadArray[Char](dump(Array('a')))) + println("Array(1)="+loadArray[Int](dump(Array(1)))) + println() + + println("((),())="+load[(Unit, Unit)](dump(((), ())))) + println("(true,false)="+load[(Boolean, Boolean)](dump((true, false)))) + println() + + println("List(List(1), List(2))="+load[List[List[Int]]](dump(List(List(1), List(2))))) + println() + + println("Array(Array(1), Array(2))="+loadArray[Array[Int]](dump(Array(Array(1), Array(2))))) + println() +} + +trait TestUtil { + import java.io._ + def write[A](o: A): Array[Byte] = { + val ba = new ByteArrayOutputStream(512) + val out = new ObjectOutputStream(ba) + out.writeObject(o) + out.close() + ba.toByteArray() + } + def read[A](buffer: Array[Byte]): A = { + val in = new ObjectInputStream(new ByteArrayInputStream(buffer)) + in.readObject().asInstanceOf[A] + } + import scala.reflect._ + def print[T](x: T)(implicit t: ConcreteTypeTag[T]) { + // todo. type tags are not yet serializable +// val t1: ConcreteTypeTag[T] = read(write(t)) + val t1: ConcreteTypeTag[T] = t + val x1 = x.toString.replaceAll("@[0-9a-z]+$", "") + println("x="+x1+", t="+t1+", k="+t1.tpe.kind+", s="+t1.sym.toString) + } +} diff --git a/test/files/jvm/manifests.check b/test/files/jvm/manifests.check deleted file mode 100644 index be8ec2bb5b..0000000000 --- a/test/files/jvm/manifests.check +++ /dev/null @@ -1,56 +0,0 @@ -x=(), m=ConcreteTypeTag[Unit], k=TypeRef, s=class Unit -x=true, m=ConcreteTypeTag[Boolean], k=TypeRef, s=class Boolean -x=a, m=ConcreteTypeTag[Char], k=TypeRef, s=class Char -x=1, m=ConcreteTypeTag[Int], k=TypeRef, s=class Int -x=abc, m=ConcreteTypeTag[String], k=TypeRef, s=class String -x='abc, m=ConcreteTypeTag[Symbol], k=TypeRef, s=class Symbol - -x=List(()), m=ConcreteTypeTag[List[Unit]], k=TypeRef, s=class List -x=List(true), m=ConcreteTypeTag[List[Boolean]], k=TypeRef, s=class List -x=List(1), m=ConcreteTypeTag[List[Int]], k=TypeRef, s=class List -x=List(abc), m=ConcreteTypeTag[List[String]], k=TypeRef, s=class List -x=List('abc), m=ConcreteTypeTag[List[Symbol]], k=TypeRef, s=class List - -x=[Z, m=ConcreteTypeTag[Array[Boolean]], k=TypeRef, s=class Array -x=[C, m=ConcreteTypeTag[Array[Char]], k=TypeRef, s=class Array -x=[I, m=ConcreteTypeTag[Array[Int]], k=TypeRef, s=class Array -x=[Ljava.lang.String;, m=ConcreteTypeTag[Array[String]], k=TypeRef, s=class Array -x=[Lscala.Symbol;, m=ConcreteTypeTag[Array[Symbol]], k=TypeRef, s=class Array - -x=((),()), m=ConcreteTypeTag[(Unit, Unit)], k=TypeRef, s=class Tuple2 -x=(true,false), m=ConcreteTypeTag[(Boolean, Boolean)], k=TypeRef, s=class Tuple2 -x=(1,2), m=ConcreteTypeTag[(Int, Int)], k=TypeRef, s=class Tuple2 -x=(abc,xyz), m=ConcreteTypeTag[(String, String)], k=TypeRef, s=class Tuple2 -x=('abc,'xyz), m=ConcreteTypeTag[(Symbol, Symbol)], k=TypeRef, s=class Tuple2 - - -x=Foo, m=ConcreteTypeTag[Foo[Int]], k=TypeRef, s=class Foo -x=Foo, m=ConcreteTypeTag[Foo[List[Int]]], k=TypeRef, s=class Foo -x=Foo, m=ConcreteTypeTag[Foo[Foo[Int]]], k=TypeRef, s=class Foo -x=Foo, m=ConcreteTypeTag[Foo[List[Foo[Int]]]], k=TypeRef, s=class Foo - -x=Test1$$anon$1, m=ConcreteTypeTag[Bar[String]], k=RefinedType, s= -x=Test1$$anon$2, m=ConcreteTypeTag[Bar[String]], k=RefinedType, s= - -()=() -true=true -a=a -1=1 -'abc='abc - -List(())=List(()) -List(true)=List(true) -List('abc)=List('abc) - -Array()=Array() -Array(true)=Array(true) -Array(a)=Array(a) -Array(1)=Array(1) - -((),())=((),()) -(true,false)=(true,false) - -List(List(1), List(2))=List(List(1), List(2)) - -Array(Array(1), Array(2))=Array(Array(1), Array(2)) - diff --git a/test/files/jvm/manifests.scala b/test/files/jvm/manifests.scala deleted file mode 100644 index 935427f5d4..0000000000 --- a/test/files/jvm/manifests.scala +++ /dev/null @@ -1,112 +0,0 @@ -object Test extends App { - Test1 - Test2 -} - -class Foo[T](x: T) -trait Bar[T] { def f: T } - -object Test1 extends TestUtil { - print(()) - print(true) - print('a') - print(1) - print("abc") - print('abc) - println() - - print(List(())) - print(List(true)) - print(List(1)) - print(List("abc")) - print(List('abc)) - println() - - //print(Array(())) //Illegal class name "[V" in class file Test$ - print(Array(true)) - print(Array('a')) - print(Array(1)) - print(Array("abc")) - print(Array('abc)) - println() - - print(((), ())) - print((true, false)) - print((1, 2)) - print(("abc", "xyz")) - print(('abc, 'xyz)) - println() - - // Disabled: should these work? changing the inference for objects from - // "object Test" to "Test.type" drags in a singleton manifest which for - // some reason leads to serialization failure. - // print(Test) - // print(List) - println() - - print(new Foo(2)) - print(new Foo(List(2))) - print(new Foo(new Foo(2))) - print(new Foo(List(new Foo(2)))) - println() - - print(new Bar[String] { def f = "abc" }); - {print(new Bar[String] { def f = "abc" })} - println() -} - -object Test2 { - import scala.util.Marshal._ - println("()="+load[Unit](dump(()))) - println("true="+load[Boolean](dump(true))) - println("a="+load[Char](dump('a'))) - println("1="+load[Int](dump(1))) - println("'abc="+load[Symbol](dump('abc))) - println() - - println("List(())="+load[List[Unit]](dump(List(())))) - println("List(true)="+load[List[Boolean]](dump(List(true)))) - println("List('abc)="+load[List[Symbol]](dump(List('abc)))) - println() - - def loadArray[T](x: Array[Byte])(implicit m: reflect.Manifest[Array[T]]) = - load[Array[T]](x)(m).deep.toString - println("Array()="+loadArray[Int](dump(Array(): Array[Int]))) - println("Array(true)="+loadArray[Boolean](dump(Array(true)))) - println("Array(a)="+loadArray[Char](dump(Array('a')))) - println("Array(1)="+loadArray[Int](dump(Array(1)))) - println() - - println("((),())="+load[(Unit, Unit)](dump(((), ())))) - println("(true,false)="+load[(Boolean, Boolean)](dump((true, false)))) - println() - - println("List(List(1), List(2))="+load[List[List[Int]]](dump(List(List(1), List(2))))) - println() - - println("Array(Array(1), Array(2))="+loadArray[Array[Int]](dump(Array(Array(1), Array(2))))) - println() -} - -trait TestUtil { - import java.io._ - def write[A](o: A): Array[Byte] = { - val ba = new ByteArrayOutputStream(512) - val out = new ObjectOutputStream(ba) - out.writeObject(o) - out.close() - ba.toByteArray() - } - def read[A](buffer: Array[Byte]): A = { - val in = new ObjectInputStream(new ByteArrayInputStream(buffer)) - in.readObject().asInstanceOf[A] - } - import scala.reflect._ - def print[T](x: T)(implicit m: Manifest[T]) { - // manifests are no longer serializable -// val m1: Manifest[T] = read(write(m)) - val m1: Manifest[T] = m - val x1 = x.toString.replaceAll("@[0-9a-z]+$", "") - println("x="+x1+", m="+m1+", k="+m1.tpe.kind+", s="+m1.sym.toString) - } -} diff --git a/test/files/jvm/serialization-new.check b/test/files/jvm/serialization-new.check new file mode 100644 index 0000000000..fa51c6a879 --- /dev/null +++ b/test/files/jvm/serialization-new.check @@ -0,0 +1,313 @@ +a1 = Array[1,2,3] +_a1 = Array[1,2,3] +arrayEquals(a1, _a1): true + +e1 = Left(1) +_e1 = Left(1) +e1 eq _e1: false, _e1 eq e1: false +e1 equals _e1: true, _e1 equals e1: true + +x7 = RoundingMode +y7 = RoundingMode +x7 eq y7: true, y7 eq x7: true +x7 equals y7: true, y7 equals x7: true + +x8 = WeekDay +y8 = WeekDay +x8 eq y8: true, y8 eq x8: true +x8 equals y8: true, y8 equals x8: true + +x9 = UP +y9 = UP +x9 eq y9: true, y9 eq x9: true +x9 equals y9: true, y9 equals x9: true + +x10 = Monday +y10 = Monday +x10 eq y10: true, y10 eq x10: true +x10 equals y10: true, y10 equals x10: true + +x9 eq x10: false, x10 eq x9: false +x9 equals x10: false, x10 equals x9: false +x9 eq y10: false, y10 eq x9: false +x9 equals y10: false, y10 equals x9: false + +f1 = +_f1 = +f1(2): 4, _f1(2): 4 + +xs0 = List(1, 2, 3) +_xs0 = List(1, 2, 3) +xs0 eq _xs0: false, _xs0 eq xs0: false +xs0 equals _xs0: true, _xs0 equals xs0: true + +xs1 = List() +_xs1 = List() +xs1 eq _xs1: true, _xs1 eq xs1: true + +o1 = None +_o1 = None +o1 eq _o1: true, _o1 eq o1: true + +o2 = Some(1) +_o2 = Some(1) +o2 eq _o2: false, _o2 eq o2: false +o2 equals _o2: true, _o2 equals o2: true + +s1 = 'hello +_s1 = 'hello +s1 eq _s1: true, _s1 eq s1: true +s1 equals _s1: true, _s1 equals s1: true + +t1 = (BannerLimit,12345) +_t1 = (BannerLimit,12345) +t1 eq _t1: false, _t1 eq t1: false +t1 equals _t1: true, _t1 equals t1: true + +x = BitSet(1, 2) +y = BitSet(1, 2) +x equals y: true, y equals x: true + +x = BitSet(2, 3) +y = BitSet(2, 3) +x equals y: true, y equals x: true + +x = Map(1 -> A, 2 -> B, 3 -> C) +y = Map(1 -> A, 2 -> B, 3 -> C) +x equals y: true, y equals x: true + +x = Set(1, 2) +y = Set(1, 2) +x equals y: true, y equals x: true + +x = List((buffers,20), (layers,2), (title,3)) +y = List((buffers,20), (layers,2), (title,3)) +x equals y: true, y equals x: true + +x = Map(buffers -> 20, layers -> 2, title -> 3) +y = Map(buffers -> 20, layers -> 2, title -> 3) +x equals y: true, y equals x: true + +x = ListSet(5, 3) +y = ListSet(5, 3) +x equals y: true, y equals x: true + +x = Queue(a, b, c) +y = Queue(a, b, c) +x equals y: true, y equals x: true + +x = Range(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) +y = Range(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) +x equals y: true, y equals x: true + +x = NumericRange(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) +y = NumericRange(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) +x equals y: true, y equals x: true + +x = Map(1 -> A, 2 -> B, 3 -> C) +y = Map(1 -> A, 2 -> B, 3 -> C) +x equals y: true, y equals x: true + +x = TreeSet(1, 2, 3) +y = TreeSet(1, 2, 3) +x equals y: true, y equals x: true + +x = Stack(c, b, a) +y = Stack(c, b, a) +x equals y: true, y equals x: true + +x = Stream(0, ?) +y = Stream(0, ?) +x equals y: true, y equals x: true + +x = Map(42 -> FortyTwo) +y = Map(42 -> FortyTwo) +x equals y: true, y equals x: true + +x = TreeSet(0, 2) +y = TreeSet(0, 2) +x equals y: true, y equals x: true + +x = Vector('a, 'b, 'c) +y = Vector('a, 'b, 'c) +x equals y: true, y equals x: true + +x = ArrayBuffer(one, two) +y = ArrayBuffer(one, two) +x equals y: true, y equals x: true + +x = ArrayBuilder.ofLong +y = ArrayBuilder.ofLong +x equals y: true, y equals x: true + +x = ArrayBuilder.ofFloat +y = ArrayBuilder.ofFloat +x equals y: true, y equals x: true + +x = ArraySeq(1, 2, 3) +y = ArraySeq(1, 2, 3) +x equals y: true, y equals x: true + +x = ArrayStack(3, 2, 20) +y = ArrayStack(3, 2, 20) +x equals y: true, y equals x: true + +x = BitSet(0, 8, 9) +y = BitSet(0, 8, 9) +x equals y: true, y equals x: true + +x = Map(A -> 1, C -> 3, B -> 2) +y = Map(A -> 1, C -> 3, B -> 2) +x equals y: true, y equals x: true + +x = Set(buffers, title, layers) +y = Set(buffers, title, layers) +x equals y: true, y equals x: true + +x = History() +y = History() +x equals y: true, y equals x: true + +x = ListBuffer(white, black) +y = ListBuffer(white, black) +x equals y: true, y equals x: true + +x = Queue(20, 2, 3) +y = Queue(20, 2, 3) +x equals y: true, y equals x: true + +x = Stack(3, 2, 20) +y = Stack(3, 2, 20) +x equals y: true, y equals x: true + +x = abc +y = abc +x equals y: true, y equals x: true + +x = WrappedArray(1, 2, 3) +y = WrappedArray(1, 2, 3) +x equals y: true, y equals x: true + +x = TreeSet(1, 2, 3) +y = TreeSet(1, 2, 3) +x equals y: true, y equals x: true + +x = TrieMap(1 -> one, 2 -> two, 3 -> three) +y = TrieMap(1 -> one, 2 -> two, 3 -> three) +x equals y: true, y equals x: true + +x = xml:src="hello" +y = xml:src="hello" +x equals y: true, y equals x: true + +x = +y = +x equals y: true, y equals x: true + +x = title +y = title +x equals y: true, y equals x: true + +x = + + + + + + + + + + + + + + + + +
Last NameFirst Name
Tom 20
Bob 22
James 19
+ + +y = + + + + + + + + + + + + + + + + +
Last NameFirst Name
Tom 20
Bob 22
James 19
+ + +x equals y: true, y equals x: true + +x = Tim +y = Tim +x equals y: true, y equals x: true + +x = Bob +y = Bob +x equals y: true, y equals x: true + +x = John +y = John +x equals y: true, y equals x: true + +x = Bill +y = Bill +x equals y: true, y equals x: true + +x = Paul +y = Paul +x equals y: true, y equals x: true + +1 +2 +1 +2 + +x = UnrolledBuffer(one, two) +y = UnrolledBuffer(one, two) +x equals y: true, y equals x: true + +x = ParArray(abc, def, etc) +y = ParArray(abc, def, etc) +x equals y: true, y equals x: true + +x = ParHashMap(2 -> 4, 1 -> 2) +y = ParHashMap(2 -> 4, 1 -> 2) +x equals y: true, y equals x: true + +x = ParTrieMap(1 -> 2, 2 -> 4) +y = ParTrieMap(1 -> 2, 2 -> 4) +x equals y: true, y equals x: true + +x = ParHashSet(1, 2, 3) +y = ParHashSet(1, 2, 3) +x equals y: true, y equals x: true + +x = ParRange(0, 1, 2, 3, 4) +y = ParRange(0, 1, 2, 3, 4) +x equals y: true, y equals x: true + +x = ParRange(0, 1, 2, 3) +y = ParRange(0, 1, 2, 3) +x equals y: true, y equals x: true + +x = ParMap(5 -> 1, 10 -> 2) +y = ParMap(5 -> 1, 10 -> 2) +x equals y: true, y equals x: true + +x = ParSet(two, one) +y = ParSet(two, one) +x equals y: true, y equals x: true + diff --git a/test/files/jvm/serialization-new.scala b/test/files/jvm/serialization-new.scala new file mode 100644 index 0000000000..bb971fdf36 --- /dev/null +++ b/test/files/jvm/serialization-new.scala @@ -0,0 +1,651 @@ +//############################################################################ +// Serialization +//############################################################################ + +object Serialize { + @throws(classOf[java.io.IOException]) + def write[A](o: A): Array[Byte] = { + val ba = new java.io.ByteArrayOutputStream(512) + val out = new java.io.ObjectOutputStream(ba) + out.writeObject(o) + out.close() + ba.toByteArray() + } + @throws(classOf[java.io.IOException]) + @throws(classOf[ClassNotFoundException]) + def read[A](buffer: Array[Byte]): A = { + val in = + new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer)) + in.readObject().asInstanceOf[A] + } + def check[A, B](x: A, y: B) { + println("x = " + x) + println("y = " + y) + println("x equals y: " + (x equals y) + ", y equals x: " + (y equals x)) + assert((x equals y) && (y equals x)) + println() + } +} +import Serialize._ + +//############################################################################ +// Test classes in package "scala" + +object Test1_scala { + + private def arrayToString[A](arr: Array[A]): String = + arr.mkString("Array[",",","]") + + private def arrayEquals[A, B](a1: Array[A], a2: Array[B]): Boolean = + (a1.length == a2.length) && + (Iterator.range(0, a1.length) forall { i => a1(i) == a2(i) }) + + object WeekDay extends Enumeration { + type WeekDay = Value + val Monday, Tuesday, Wednesday, Thusday, Friday, Saturday, Sunday = Value + } + import WeekDay._, BigDecimal._, RoundingMode._ + + // in alphabetic order + try { + // Array + val a1 = Array(1, 2, 3) + val _a1: Array[Int] = read(write(a1)) + println("a1 = " + arrayToString(a1)) + println("_a1 = " + arrayToString(_a1)) + println("arrayEquals(a1, _a1): " + arrayEquals(a1, _a1)) + println() + + // Either + val e1 = Left(1) + val _e1: Either[Int, String] = read(write(e1)) + println("e1 = " + e1) + println("_e1 = " + _e1) + println("e1 eq _e1: " + (e1 eq _e1) + ", _e1 eq e1: " + (_e1 eq e1)) + println("e1 equals _e1: " + (e1 equals _e1) + ", _e1 equals e1: " + (_e1 equals e1)) + println() + + // Enumeration + val x7 = BigDecimal.RoundingMode + val y7: RoundingMode.type = read(write(x7)) + println("x7 = " + x7) + println("y7 = " + y7) + println("x7 eq y7: " + (x7 eq y7) + ", y7 eq x7: " + (y7 eq x7)) + println("x7 equals y7: " + (x7 equals y7) + ", y7 equals x7: " + (y7 equals x7)) + println() + + val x8 = WeekDay + val y8: WeekDay.type = read(write(x8)) + println("x8 = " + x8) + println("y8 = " + y8) + println("x8 eq y8: " + (x8 eq y8) + ", y8 eq x8: " + (y8 eq x8)) + println("x8 equals y8: " + (x8 equals y8) + ", y8 equals x8: " + (y8 equals x8)) + println() + + val x9 = UP + val y9: RoundingMode = read(write(x9)) + println("x9 = " + x9) + println("y9 = " + y9) + println("x9 eq y9: " + (x9 eq y9) + ", y9 eq x9: " + (y9 eq x9)) + println("x9 equals y9: " + (x9 equals y9) + ", y9 equals x9: " + (y9 equals x9)) + println() + + val x10 = Monday + val y10: WeekDay = read(write(x10)) + println("x10 = " + x10) + println("y10 = " + y10) + println("x10 eq y10: " + (x10 eq y10) + ", y10 eq x10: " + (y10 eq x10)) + println("x10 equals y10: " + (x10 equals y10) + ", y10 equals x10: " + (y10 equals x10)) + println() + + println("x9 eq x10: " + (x9 eq x10) + ", x10 eq x9: " + (x10 eq x9)) + println("x9 equals x10: " + (x9 equals x10) + ", x10 equals x9: " + (x10 equals x9)) + println("x9 eq y10: " + (x9 eq y10) + ", y10 eq x9: " + (y10 eq x9)) + println("x9 equals y10: " + (x9 equals y10) + ", y10 equals x9: " + (y10 equals x9)) + println() + + // Function + val f1 = { x: Int => 2 * x } + val _f1: Function[Int, Int] = read(write(f1)) + println("f1 = ") + println("_f1 = ") + println("f1(2): " + f1(2) + ", _f1(2): " + _f1(2)) + println() + + // List + val xs0 = List(1, 2, 3) + val _xs0: List[Int] = read(write(xs0)) + println("xs0 = " + xs0) + println("_xs0 = " + _xs0) + println("xs0 eq _xs0: " + (xs0 eq _xs0) + ", _xs0 eq xs0: " + (_xs0 eq xs0)) + println("xs0 equals _xs0: " + (xs0 equals _xs0) + ", _xs0 equals xs0: " + (_xs0 equals xs0)) + println() + + val xs1 = Nil + val _xs1: List[Nothing] = read(write(xs1)) + println("xs1 = " + xs1) + println("_xs1 = " + _xs1) + println("xs1 eq _xs1: " + (xs1 eq _xs1) + ", _xs1 eq xs1: " + (_xs1 eq xs1)) + println() + + // Option + val o1 = None + val _o1: Option[Nothing] = read(write(o1)) + println("o1 = " + o1) + println("_o1 = " + _o1) + println("o1 eq _o1: " + (o1 eq _o1) + ", _o1 eq o1: " + (_o1 eq o1)) + println() + + val o2 = Some(1) + val _o2: Option[Int] = read(write(o2)) + println("o2 = " + o2) + println("_o2 = " + _o2) + println("o2 eq _o2: " + (o2 eq _o2) + ", _o2 eq o2: " + (_o2 eq o2)) + println("o2 equals _o2: " + (o2 equals _o2) + ", _o2 equals o2: " + (_o2 equals o2)) + println() +/* + // Responder + val r1 = Responder.constant("xyz") + val _r1: Responder[String] = read(write(r1)) + check(r1, _r1) +*/ + // Symbol + val s1 = 'hello + val _s1: Symbol = read(write(s1)) + println("s1 = " + s1) + println("_s1 = " + _s1) + println("s1 eq _s1: " + (s1 eq _s1) + ", _s1 eq s1: " + (_s1 eq s1)) + println("s1 equals _s1: " + (s1 equals _s1) + ", _s1 equals s1: " + (_s1 equals s1)) + println() + + // Tuple + val t1 = ("BannerLimit", 12345) + val _t1: (String, Int) = read(write(t1)) + println("t1 = " + t1) + println("_t1 = " + _t1) + println("t1 eq _t1: " + (t1 eq _t1) + ", _t1 eq t1: " + (_t1 eq t1)) + println("t1 equals _t1: " + (t1 equals _t1) + ", _t1 equals t1: " + (_t1 equals t1)) + println() + } + catch { + case e: Exception => + println("Error in Test1_scala: " + e) + throw e + } +} + +//############################################################################ +// Test classes in package "scala.collection.immutable" + +object Test2_immutable { + import scala.collection.immutable.{ + BitSet, HashMap, HashSet, ListMap, ListSet, Queue, Range, SortedMap, + SortedSet, Stack, Stream, TreeMap, TreeSet, Vector} + + // in alphabetic order + try { + // BitSet + val bs1 = BitSet.empty + 1 + 2 + val _bs1: BitSet = read(write(bs1)) + check(bs1, _bs1) + + val bs2 = { + val bs = new collection.mutable.BitSet() + bs += 2; bs += 3 + bs.toImmutable + } + val _bs2: BitSet = read(write(bs2)) + check(bs2, _bs2) + + // HashMap + val hm1 = new HashMap[Int, String] + (1 -> "A", 2 -> "B", 3 -> "C") + val _hm1: HashMap[Int, String] = read(write(hm1)) + check(hm1, _hm1) + + // HashSet + val hs1 = new HashSet[Int] + 1 + 2 + val _hs1: HashSet[Int] = read(write(hs1)) + check(hs1, _hs1) + + // List + val xs1 = List(("buffers", 20), ("layers", 2), ("title", 3)) + val _xs1: List[(String, Int)] = read(write(xs1)) + check(xs1, _xs1) + + // ListMap + val lm1 = new ListMap[String, Int] + ("buffers" -> 20, "layers" -> 2, "title" -> 3) + val _lm1: ListMap[String, Int] = read(write(lm1)) + check(lm1, _lm1) + + // ListSet + val ls1 = new ListSet[Int] + 3 + 5 + val _ls1: ListSet[Int] = read(write(ls1)) + check(ls1, _ls1) + + // Queue + val q1 = Queue("a", "b", "c") + val _q1: Queue[String] = read(write(q1)) + check(q1, _q1) + + // Range + val r1 = 0 until 10 + val _r1: Range = read(write(r1)) + check(r1, _r1) + + val r2 = Range.Long(0L, 10L, 1) + val _r2: r2.type = read(write(r2)) + check(r2, _r2) + + // SortedMap + val sm1 = SortedMap.empty[Int, String] + (2 -> "B", 3 -> "C", 1 -> "A") + val _sm1: SortedMap[Int, String] = read(write(sm1)) + check(sm1, _sm1) + + // SortedSet + val ss1 = SortedSet.empty[Int] + 2 + 3 + 1 + val _ss1: SortedSet[Int] = read(write(ss1)) + check(ss1, _ss1) + + // Stack + val s1 = new Stack().push("a", "b", "c") + val _s1: Stack[String] = read(write(s1)) + check(s1, _s1) + + // Stream + val st1 = Stream.range(0, 10) + val _st1: Stream[Int] = read(write(st1)) + check(st1, _st1) + + // TreeMap + val tm1 = new TreeMap[Int, String] + (42 -> "FortyTwo") + val _tm1: TreeMap[Int, String] = read(write(tm1)) + check(tm1, _tm1) + + // TreeSet + val ts1 = new TreeSet[Int]() + 2 + 0 + val _ts1: TreeSet[Int] = read(write(ts1)) + check(ts1, _ts1) + + // Vector + val v1 = Vector('a, 'b, 'c) + val _v1: Vector[Symbol] = read(write(v1)) + check(v1, _v1) + } + catch { + case e: Exception => + println("Error in Test2_immutable: " + e) + throw e + } +} + +//############################################################################ +// Test classes in package "scala.collection.mutable" + +object Test3_mutable { + import scala.reflect.ArrayTag + import scala.collection.mutable.{ + ArrayBuffer, ArrayBuilder, ArraySeq, ArrayStack, BitSet, DoubleLinkedList, + HashMap, HashSet, History, LinkedList, ListBuffer, Publisher, Queue, + Stack, StringBuilder, WrappedArray, TreeSet} + import scala.collection.concurrent.TrieMap + + // in alphabetic order + try { + // ArrayBuffer + val ab1 = new ArrayBuffer[String] + ab1 ++= List("one", "two") + val _ab1: ArrayBuffer[String] = read(write(ab1)) + check(ab1, _ab1) + + // ArrayBuilder + val abu1 = ArrayBuilder.make[Long] + val _abu1: ArrayBuilder[ArrayTag[Long]] = read(write(abu1)) + check(abu1, _abu1) + + val abu2 = ArrayBuilder.make[Float] + val _abu2: ArrayBuilder[ArrayTag[Float]] = read(write(abu2)) + check(abu2, _abu2) + + // ArraySeq + val aq1 = ArraySeq(1, 2, 3) + val _aq1: ArraySeq[Int] = read(write(aq1)) + check(aq1, _aq1) + + // ArrayStack + val as1 = new ArrayStack[Int] + as1 ++= List(20, 2, 3).iterator + val _as1: ArrayStack[Int] = read(write(as1)) + check(as1, _as1) + + // BitSet + val bs1 = new BitSet() + bs1 += 0 + bs1 += 8 + bs1 += 9 + val _bs1: BitSet = read(write(bs1)) + check(bs1, _bs1) +/* + // DoubleLinkedList + val dl1 = new DoubleLinkedList[Int](2, null) + dl1.append(new DoubleLinkedList(3, null)) + val _dl1: DoubleLinkedList[Int] = read(write(dl1)) + check(dl1, _dl1) +*/ + // HashMap + val hm1 = new HashMap[String, Int] + hm1 ++= List(("A", 1), ("B", 2), ("C", 3)).iterator + val _hm1: HashMap[String, Int] = read(write(hm1)) + check(hm1, _hm1) + + // HashSet + val hs1 = new HashSet[String] + hs1 ++= List("layers", "buffers", "title").iterator + val _hs1: HashSet[String] = read(write(hs1)) + check(hs1, _hs1) + + val h1 = new History[String, Int] + val _h1: History[String, Int] = read(write(h1)) + check(h1, _h1) +/* + // LinkedList + val ll1 = new LinkedList[Int](2, null) + ll1.append(new LinkedList(3, null)) + val _ll1: LinkedList[Int] = read(write(ll1)) + check(ll1, _ll1) +*/ + // ListBuffer + val lb1 = new ListBuffer[String] + lb1 ++= List("white", "black") + val _lb1: ListBuffer[String] = read(write(lb1)) + check(lb1, _lb1) + + // Queue + val q1 = new Queue[Int] + q1 ++= List(20, 2, 3).iterator + val _q1: Queue[Int] = read(write(q1)) + check(q1, _q1) + + // Stack + val s1 = new Stack[Int] + s1 pushAll q1 + val _s1: Stack[Int] = read(write(s1)) + check(s1, _s1) + + // StringBuilder + val sb1 = new StringBuilder + sb1 append "abc" + val _sb1: StringBuilder = read(write(sb1)) + check(sb1, _sb1) + + // WrappedArray + val wa1 = WrappedArray.make(Array(1, 2, 3)) + val _wa1: WrappedArray[Int] = read(write(wa1)) + check(wa1, _wa1) + + // TreeSet + val ts1 = TreeSet[Int]() ++= Array(1, 2, 3) + val _ts1: TreeSet[Int] = read(write(ts1)) + check(ts1, _ts1) + + // concurrent.TrieMap + val ct1 = TrieMap[Int, String]() ++= Array(1 -> "one", 2 -> "two", 3 -> "three") + val _ct1: TrieMap[Int, String] = read(write(ct1)) + check(ct1, _ct1) + } + catch { + case e: Exception => + println("Error in Test3_mutable: " + e) + throw e + } +} + + +//############################################################################ +// Test classes in package "scala.xml" + +object Test4_xml { + import scala.xml.{Attribute, Document, Elem, Null, PrefixedAttribute, Text} + + case class Person(name: String, age: Int) + + try { + // Attribute + val a1 = new PrefixedAttribute("xml", "src", Text("hello"), Null) + val _a1: Attribute = read(write(a1)) + check(a1, _a1) + + // Document + val d1 = new Document + d1.docElem = + d1.encoding = Some("UTF-8") + val _d1: Document = read(write(d1)) + check(d1, _d1) + + // Elem + val e1 = title; + val _e1: Elem = read(write(e1)) + check(e1, _e1) + + class AddressBook(a: Person*) { + private val people: List[Person] = a.toList + def toXHTML = + + + + + + { for (p <- people) yield + + + + } +
Last NameFirst Name
{ p.name } { p.age.toString() }
; + } + + val people = new AddressBook( + Person("Tom", 20), + Person("Bob", 22), + Person("James", 19)) + + val e2 = + + + { people.toXHTML } + + ; + val _e2: Elem = read(write(e2)) + check(e2, _e2) + } + catch { + case e: Exception => + println("Error in Test4_xml: " + e) + throw e + } +} + +//############################################################################ +// Test user-defined classes WITHOUT nesting + +class Person(_name: String) extends Serializable { + private var name = _name + override def toString() = name + override def equals(that: Any): Boolean = + that.isInstanceOf[Person] && + (name == that.asInstanceOf[Person].name) +} + +class Employee(_name: String) extends Serializable { + private var name = _name + override def toString() = name +} + +object bob extends Employee("Bob") + +object Test5 { + val x1 = new Person("Tim") + val x2 = bob + + try { + val y1: Person = read(write(x1)) + val y2: Employee = read(write(x2)) + + check(x1, y1) + check(x2, y2) + } + catch { + case e: Exception => + println("Error in Test5: " + e) + } +} + +//############################################################################ +// Test user-defined classes WITH nesting + +object Test6 { + object bill extends Employee("Bill") { + val x = paul + } + object paul extends Person("Paul") { + val x = 4 // bill; => StackOverflowException !!! + } + val x1 = new Person("John") + val x2 = bill + val x3 = paul + + try { + val y1: Person = read(write(x1)) + val y2: Employee = read(write(x2)) + val y3: Person = read(write(x3)) + + check(x1, y1) + check(x2, y2) + check(x3, y3) + } + catch { + case e: Exception => + println("Error in Test6: " + e) + } +} + +//############################################################################ +// Nested objects cannot get readresolve automatically because after deserialization +// they would be null (they are treated as lazy vals) +class Outer extends Serializable { + object Inner extends Serializable +} + +object Test7 { + val x = new Outer + x.Inner // initialize + val y:Outer = read(write(x)) + if (y.Inner == null) + println("Inner object is null") +} + +// Verify that transient lazy vals don't get serialized +class WithTransient extends Serializable { + @transient lazy val a1 = 1 + @transient private lazy val a2 = 2 + @transient object B extends Serializable + @transient private object C extends Serializable + + def test = { + println(a1) + println(a2) + if (B == null || C == null) + println("Transient nested object failed to serialize properly") + } +} + +object Test8 { + val x = new WithTransient + x.test + try { + val y:WithTransient = read(write(x)) + y.test + } + catch { + case e: Exception => + println("Error in Test8: " + e) + } +} + +//############################################################################ +// Test code + +object Test { + def main(args: Array[String]) { + Test1_scala + Test2_immutable + Test3_mutable + Test4_xml + Test5 + Test6 + Test7 + Test8 + Test9_parallel + } +} + +//############################################################################ + + +//############################################################################ +// Test classes in package "scala.collection.parallel" and subpackages +object Test9_parallel { + import scala.collection.parallel._ + + try { + println() + + // UnrolledBuffer + val ub = new collection.mutable.UnrolledBuffer[String] + ub ++= List("one", "two") + val _ub: collection.mutable.UnrolledBuffer[String] = read(write(ub)) + check(ub, _ub) + + // mutable.ParArray + val pa = mutable.ParArray("abc", "def", "etc") + val _pa: mutable.ParArray[String] = read(write(pa)) + check(pa, _pa) + + // mutable.ParHashMap + val mpm = mutable.ParHashMap(1 -> 2, 2 -> 4) + val _mpm: mutable.ParHashMap[Int, Int] = read(write(mpm)) + check(mpm, _mpm) + + // mutable.ParTrieMap + val mpc = mutable.ParTrieMap(1 -> 2, 2 -> 4) + val _mpc: mutable.ParTrieMap[Int, Int] = read(write(mpc)) + check(mpc, _mpc) + + // mutable.ParHashSet + val mps = mutable.ParHashSet(1, 2, 3) + val _mps: mutable.ParHashSet[Int] = read(write(mps)) + check(mps, _mps) + + // immutable.ParRange + val pr1 = immutable.ParRange(0, 4, 1, true) + val _pr1: immutable.ParRange = read(write(pr1)) + check(pr1, _pr1) + + val pr2 = immutable.ParRange(0, 4, 1, false) + val _pr2: immutable.ParRange = read(write(pr2)) + check(pr2, _pr2) + + // immutable.ParHashMap + val ipm = immutable.ParHashMap(5 -> 1, 10 -> 2) + val _ipm: immutable.ParHashMap[Int, Int] = read(write(ipm)) + check(ipm, _ipm) + + // immutable.ParHashSet + val ips = immutable.ParHashSet("one", "two") + val _ips: immutable.ParHashSet[String] = read(write(ips)) + check(ips, _ips) + + } catch { + case e: Exception => + println("Error in Test5_parallel: " + e) + throw e + } +} diff --git a/test/files/jvm/serialization.check b/test/files/jvm/serialization.check deleted file mode 100644 index fa51c6a879..0000000000 --- a/test/files/jvm/serialization.check +++ /dev/null @@ -1,313 +0,0 @@ -a1 = Array[1,2,3] -_a1 = Array[1,2,3] -arrayEquals(a1, _a1): true - -e1 = Left(1) -_e1 = Left(1) -e1 eq _e1: false, _e1 eq e1: false -e1 equals _e1: true, _e1 equals e1: true - -x7 = RoundingMode -y7 = RoundingMode -x7 eq y7: true, y7 eq x7: true -x7 equals y7: true, y7 equals x7: true - -x8 = WeekDay -y8 = WeekDay -x8 eq y8: true, y8 eq x8: true -x8 equals y8: true, y8 equals x8: true - -x9 = UP -y9 = UP -x9 eq y9: true, y9 eq x9: true -x9 equals y9: true, y9 equals x9: true - -x10 = Monday -y10 = Monday -x10 eq y10: true, y10 eq x10: true -x10 equals y10: true, y10 equals x10: true - -x9 eq x10: false, x10 eq x9: false -x9 equals x10: false, x10 equals x9: false -x9 eq y10: false, y10 eq x9: false -x9 equals y10: false, y10 equals x9: false - -f1 = -_f1 = -f1(2): 4, _f1(2): 4 - -xs0 = List(1, 2, 3) -_xs0 = List(1, 2, 3) -xs0 eq _xs0: false, _xs0 eq xs0: false -xs0 equals _xs0: true, _xs0 equals xs0: true - -xs1 = List() -_xs1 = List() -xs1 eq _xs1: true, _xs1 eq xs1: true - -o1 = None -_o1 = None -o1 eq _o1: true, _o1 eq o1: true - -o2 = Some(1) -_o2 = Some(1) -o2 eq _o2: false, _o2 eq o2: false -o2 equals _o2: true, _o2 equals o2: true - -s1 = 'hello -_s1 = 'hello -s1 eq _s1: true, _s1 eq s1: true -s1 equals _s1: true, _s1 equals s1: true - -t1 = (BannerLimit,12345) -_t1 = (BannerLimit,12345) -t1 eq _t1: false, _t1 eq t1: false -t1 equals _t1: true, _t1 equals t1: true - -x = BitSet(1, 2) -y = BitSet(1, 2) -x equals y: true, y equals x: true - -x = BitSet(2, 3) -y = BitSet(2, 3) -x equals y: true, y equals x: true - -x = Map(1 -> A, 2 -> B, 3 -> C) -y = Map(1 -> A, 2 -> B, 3 -> C) -x equals y: true, y equals x: true - -x = Set(1, 2) -y = Set(1, 2) -x equals y: true, y equals x: true - -x = List((buffers,20), (layers,2), (title,3)) -y = List((buffers,20), (layers,2), (title,3)) -x equals y: true, y equals x: true - -x = Map(buffers -> 20, layers -> 2, title -> 3) -y = Map(buffers -> 20, layers -> 2, title -> 3) -x equals y: true, y equals x: true - -x = ListSet(5, 3) -y = ListSet(5, 3) -x equals y: true, y equals x: true - -x = Queue(a, b, c) -y = Queue(a, b, c) -x equals y: true, y equals x: true - -x = Range(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) -y = Range(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) -x equals y: true, y equals x: true - -x = NumericRange(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) -y = NumericRange(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) -x equals y: true, y equals x: true - -x = Map(1 -> A, 2 -> B, 3 -> C) -y = Map(1 -> A, 2 -> B, 3 -> C) -x equals y: true, y equals x: true - -x = TreeSet(1, 2, 3) -y = TreeSet(1, 2, 3) -x equals y: true, y equals x: true - -x = Stack(c, b, a) -y = Stack(c, b, a) -x equals y: true, y equals x: true - -x = Stream(0, ?) -y = Stream(0, ?) -x equals y: true, y equals x: true - -x = Map(42 -> FortyTwo) -y = Map(42 -> FortyTwo) -x equals y: true, y equals x: true - -x = TreeSet(0, 2) -y = TreeSet(0, 2) -x equals y: true, y equals x: true - -x = Vector('a, 'b, 'c) -y = Vector('a, 'b, 'c) -x equals y: true, y equals x: true - -x = ArrayBuffer(one, two) -y = ArrayBuffer(one, two) -x equals y: true, y equals x: true - -x = ArrayBuilder.ofLong -y = ArrayBuilder.ofLong -x equals y: true, y equals x: true - -x = ArrayBuilder.ofFloat -y = ArrayBuilder.ofFloat -x equals y: true, y equals x: true - -x = ArraySeq(1, 2, 3) -y = ArraySeq(1, 2, 3) -x equals y: true, y equals x: true - -x = ArrayStack(3, 2, 20) -y = ArrayStack(3, 2, 20) -x equals y: true, y equals x: true - -x = BitSet(0, 8, 9) -y = BitSet(0, 8, 9) -x equals y: true, y equals x: true - -x = Map(A -> 1, C -> 3, B -> 2) -y = Map(A -> 1, C -> 3, B -> 2) -x equals y: true, y equals x: true - -x = Set(buffers, title, layers) -y = Set(buffers, title, layers) -x equals y: true, y equals x: true - -x = History() -y = History() -x equals y: true, y equals x: true - -x = ListBuffer(white, black) -y = ListBuffer(white, black) -x equals y: true, y equals x: true - -x = Queue(20, 2, 3) -y = Queue(20, 2, 3) -x equals y: true, y equals x: true - -x = Stack(3, 2, 20) -y = Stack(3, 2, 20) -x equals y: true, y equals x: true - -x = abc -y = abc -x equals y: true, y equals x: true - -x = WrappedArray(1, 2, 3) -y = WrappedArray(1, 2, 3) -x equals y: true, y equals x: true - -x = TreeSet(1, 2, 3) -y = TreeSet(1, 2, 3) -x equals y: true, y equals x: true - -x = TrieMap(1 -> one, 2 -> two, 3 -> three) -y = TrieMap(1 -> one, 2 -> two, 3 -> three) -x equals y: true, y equals x: true - -x = xml:src="hello" -y = xml:src="hello" -x equals y: true, y equals x: true - -x = -y = -x equals y: true, y equals x: true - -x = title -y = title -x equals y: true, y equals x: true - -x = - - - - - - - - - - - - - - - - -
Last NameFirst Name
Tom 20
Bob 22
James 19
- - -y = - - - - - - - - - - - - - - - - -
Last NameFirst Name
Tom 20
Bob 22
James 19
- - -x equals y: true, y equals x: true - -x = Tim -y = Tim -x equals y: true, y equals x: true - -x = Bob -y = Bob -x equals y: true, y equals x: true - -x = John -y = John -x equals y: true, y equals x: true - -x = Bill -y = Bill -x equals y: true, y equals x: true - -x = Paul -y = Paul -x equals y: true, y equals x: true - -1 -2 -1 -2 - -x = UnrolledBuffer(one, two) -y = UnrolledBuffer(one, two) -x equals y: true, y equals x: true - -x = ParArray(abc, def, etc) -y = ParArray(abc, def, etc) -x equals y: true, y equals x: true - -x = ParHashMap(2 -> 4, 1 -> 2) -y = ParHashMap(2 -> 4, 1 -> 2) -x equals y: true, y equals x: true - -x = ParTrieMap(1 -> 2, 2 -> 4) -y = ParTrieMap(1 -> 2, 2 -> 4) -x equals y: true, y equals x: true - -x = ParHashSet(1, 2, 3) -y = ParHashSet(1, 2, 3) -x equals y: true, y equals x: true - -x = ParRange(0, 1, 2, 3, 4) -y = ParRange(0, 1, 2, 3, 4) -x equals y: true, y equals x: true - -x = ParRange(0, 1, 2, 3) -y = ParRange(0, 1, 2, 3) -x equals y: true, y equals x: true - -x = ParMap(5 -> 1, 10 -> 2) -y = ParMap(5 -> 1, 10 -> 2) -x equals y: true, y equals x: true - -x = ParSet(two, one) -y = ParSet(two, one) -x equals y: true, y equals x: true - diff --git a/test/files/jvm/serialization.scala b/test/files/jvm/serialization.scala deleted file mode 100644 index 9c2f2acdbf..0000000000 --- a/test/files/jvm/serialization.scala +++ /dev/null @@ -1,651 +0,0 @@ -//############################################################################ -// Serialization -//############################################################################ - -object Serialize { - @throws(classOf[java.io.IOException]) - def write[A](o: A): Array[Byte] = { - val ba = new java.io.ByteArrayOutputStream(512) - val out = new java.io.ObjectOutputStream(ba) - out.writeObject(o) - out.close() - ba.toByteArray() - } - @throws(classOf[java.io.IOException]) - @throws(classOf[ClassNotFoundException]) - def read[A](buffer: Array[Byte]): A = { - val in = - new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer)) - in.readObject().asInstanceOf[A] - } - def check[A, B](x: A, y: B) { - println("x = " + x) - println("y = " + y) - println("x equals y: " + (x equals y) + ", y equals x: " + (y equals x)) - assert((x equals y) && (y equals x)) - println() - } -} -import Serialize._ - -//############################################################################ -// Test classes in package "scala" - -object Test1_scala { - - private def arrayToString[A](arr: Array[A]): String = - arr.mkString("Array[",",","]") - - private def arrayEquals[A, B](a1: Array[A], a2: Array[B]): Boolean = - (a1.length == a2.length) && - (Iterator.range(0, a1.length) forall { i => a1(i) == a2(i) }) - - object WeekDay extends Enumeration { - type WeekDay = Value - val Monday, Tuesday, Wednesday, Thusday, Friday, Saturday, Sunday = Value - } - import WeekDay._, BigDecimal._, RoundingMode._ - - // in alphabetic order - try { - // Array - val a1 = Array(1, 2, 3) - val _a1: Array[Int] = read(write(a1)) - println("a1 = " + arrayToString(a1)) - println("_a1 = " + arrayToString(_a1)) - println("arrayEquals(a1, _a1): " + arrayEquals(a1, _a1)) - println() - - // Either - val e1 = Left(1) - val _e1: Either[Int, String] = read(write(e1)) - println("e1 = " + e1) - println("_e1 = " + _e1) - println("e1 eq _e1: " + (e1 eq _e1) + ", _e1 eq e1: " + (_e1 eq e1)) - println("e1 equals _e1: " + (e1 equals _e1) + ", _e1 equals e1: " + (_e1 equals e1)) - println() - - // Enumeration - val x7 = BigDecimal.RoundingMode - val y7: RoundingMode.type = read(write(x7)) - println("x7 = " + x7) - println("y7 = " + y7) - println("x7 eq y7: " + (x7 eq y7) + ", y7 eq x7: " + (y7 eq x7)) - println("x7 equals y7: " + (x7 equals y7) + ", y7 equals x7: " + (y7 equals x7)) - println() - - val x8 = WeekDay - val y8: WeekDay.type = read(write(x8)) - println("x8 = " + x8) - println("y8 = " + y8) - println("x8 eq y8: " + (x8 eq y8) + ", y8 eq x8: " + (y8 eq x8)) - println("x8 equals y8: " + (x8 equals y8) + ", y8 equals x8: " + (y8 equals x8)) - println() - - val x9 = UP - val y9: RoundingMode = read(write(x9)) - println("x9 = " + x9) - println("y9 = " + y9) - println("x9 eq y9: " + (x9 eq y9) + ", y9 eq x9: " + (y9 eq x9)) - println("x9 equals y9: " + (x9 equals y9) + ", y9 equals x9: " + (y9 equals x9)) - println() - - val x10 = Monday - val y10: WeekDay = read(write(x10)) - println("x10 = " + x10) - println("y10 = " + y10) - println("x10 eq y10: " + (x10 eq y10) + ", y10 eq x10: " + (y10 eq x10)) - println("x10 equals y10: " + (x10 equals y10) + ", y10 equals x10: " + (y10 equals x10)) - println() - - println("x9 eq x10: " + (x9 eq x10) + ", x10 eq x9: " + (x10 eq x9)) - println("x9 equals x10: " + (x9 equals x10) + ", x10 equals x9: " + (x10 equals x9)) - println("x9 eq y10: " + (x9 eq y10) + ", y10 eq x9: " + (y10 eq x9)) - println("x9 equals y10: " + (x9 equals y10) + ", y10 equals x9: " + (y10 equals x9)) - println() - - // Function - val f1 = { x: Int => 2 * x } - val _f1: Function[Int, Int] = read(write(f1)) - println("f1 = ") - println("_f1 = ") - println("f1(2): " + f1(2) + ", _f1(2): " + _f1(2)) - println() - - // List - val xs0 = List(1, 2, 3) - val _xs0: List[Int] = read(write(xs0)) - println("xs0 = " + xs0) - println("_xs0 = " + _xs0) - println("xs0 eq _xs0: " + (xs0 eq _xs0) + ", _xs0 eq xs0: " + (_xs0 eq xs0)) - println("xs0 equals _xs0: " + (xs0 equals _xs0) + ", _xs0 equals xs0: " + (_xs0 equals xs0)) - println() - - val xs1 = Nil - val _xs1: List[Nothing] = read(write(xs1)) - println("xs1 = " + xs1) - println("_xs1 = " + _xs1) - println("xs1 eq _xs1: " + (xs1 eq _xs1) + ", _xs1 eq xs1: " + (_xs1 eq xs1)) - println() - - // Option - val o1 = None - val _o1: Option[Nothing] = read(write(o1)) - println("o1 = " + o1) - println("_o1 = " + _o1) - println("o1 eq _o1: " + (o1 eq _o1) + ", _o1 eq o1: " + (_o1 eq o1)) - println() - - val o2 = Some(1) - val _o2: Option[Int] = read(write(o2)) - println("o2 = " + o2) - println("_o2 = " + _o2) - println("o2 eq _o2: " + (o2 eq _o2) + ", _o2 eq o2: " + (_o2 eq o2)) - println("o2 equals _o2: " + (o2 equals _o2) + ", _o2 equals o2: " + (_o2 equals o2)) - println() -/* - // Responder - val r1 = Responder.constant("xyz") - val _r1: Responder[String] = read(write(r1)) - check(r1, _r1) -*/ - // Symbol - val s1 = 'hello - val _s1: Symbol = read(write(s1)) - println("s1 = " + s1) - println("_s1 = " + _s1) - println("s1 eq _s1: " + (s1 eq _s1) + ", _s1 eq s1: " + (_s1 eq s1)) - println("s1 equals _s1: " + (s1 equals _s1) + ", _s1 equals s1: " + (_s1 equals s1)) - println() - - // Tuple - val t1 = ("BannerLimit", 12345) - val _t1: (String, Int) = read(write(t1)) - println("t1 = " + t1) - println("_t1 = " + _t1) - println("t1 eq _t1: " + (t1 eq _t1) + ", _t1 eq t1: " + (_t1 eq t1)) - println("t1 equals _t1: " + (t1 equals _t1) + ", _t1 equals t1: " + (_t1 equals t1)) - println() - } - catch { - case e: Exception => - println("Error in Test1_scala: " + e) - throw e - } -} - -//############################################################################ -// Test classes in package "scala.collection.immutable" - -object Test2_immutable { - import scala.collection.immutable.{ - BitSet, HashMap, HashSet, ListMap, ListSet, Queue, Range, SortedMap, - SortedSet, Stack, Stream, TreeMap, TreeSet, Vector} - - // in alphabetic order - try { - // BitSet - val bs1 = BitSet.empty + 1 + 2 - val _bs1: BitSet = read(write(bs1)) - check(bs1, _bs1) - - val bs2 = { - val bs = new collection.mutable.BitSet() - bs += 2; bs += 3 - bs.toImmutable - } - val _bs2: BitSet = read(write(bs2)) - check(bs2, _bs2) - - // HashMap - val hm1 = new HashMap[Int, String] + (1 -> "A", 2 -> "B", 3 -> "C") - val _hm1: HashMap[Int, String] = read(write(hm1)) - check(hm1, _hm1) - - // HashSet - val hs1 = new HashSet[Int] + 1 + 2 - val _hs1: HashSet[Int] = read(write(hs1)) - check(hs1, _hs1) - - // List - val xs1 = List(("buffers", 20), ("layers", 2), ("title", 3)) - val _xs1: List[(String, Int)] = read(write(xs1)) - check(xs1, _xs1) - - // ListMap - val lm1 = new ListMap[String, Int] + ("buffers" -> 20, "layers" -> 2, "title" -> 3) - val _lm1: ListMap[String, Int] = read(write(lm1)) - check(lm1, _lm1) - - // ListSet - val ls1 = new ListSet[Int] + 3 + 5 - val _ls1: ListSet[Int] = read(write(ls1)) - check(ls1, _ls1) - - // Queue - val q1 = Queue("a", "b", "c") - val _q1: Queue[String] = read(write(q1)) - check(q1, _q1) - - // Range - val r1 = 0 until 10 - val _r1: Range = read(write(r1)) - check(r1, _r1) - - val r2 = Range.Long(0L, 10L, 1) - val _r2: r2.type = read(write(r2)) - check(r2, _r2) - - // SortedMap - val sm1 = SortedMap.empty[Int, String] + (2 -> "B", 3 -> "C", 1 -> "A") - val _sm1: SortedMap[Int, String] = read(write(sm1)) - check(sm1, _sm1) - - // SortedSet - val ss1 = SortedSet.empty[Int] + 2 + 3 + 1 - val _ss1: SortedSet[Int] = read(write(ss1)) - check(ss1, _ss1) - - // Stack - val s1 = new Stack().push("a", "b", "c") - val _s1: Stack[String] = read(write(s1)) - check(s1, _s1) - - // Stream - val st1 = Stream.range(0, 10) - val _st1: Stream[Int] = read(write(st1)) - check(st1, _st1) - - // TreeMap - val tm1 = new TreeMap[Int, String] + (42 -> "FortyTwo") - val _tm1: TreeMap[Int, String] = read(write(tm1)) - check(tm1, _tm1) - - // TreeSet - val ts1 = new TreeSet[Int]() + 2 + 0 - val _ts1: TreeSet[Int] = read(write(ts1)) - check(ts1, _ts1) - - // Vector - val v1 = Vector('a, 'b, 'c) - val _v1: Vector[Symbol] = read(write(v1)) - check(v1, _v1) - } - catch { - case e: Exception => - println("Error in Test2_immutable: " + e) - throw e - } -} - -//############################################################################ -// Test classes in package "scala.collection.mutable" - -object Test3_mutable { - import scala.reflect.ClassManifest - import scala.collection.mutable.{ - ArrayBuffer, ArrayBuilder, ArraySeq, ArrayStack, BitSet, DoubleLinkedList, - HashMap, HashSet, History, LinkedList, ListBuffer, Publisher, Queue, - Stack, StringBuilder, WrappedArray, TreeSet} - import scala.collection.concurrent.TrieMap - - // in alphabetic order - try { - // ArrayBuffer - val ab1 = new ArrayBuffer[String] - ab1 ++= List("one", "two") - val _ab1: ArrayBuffer[String] = read(write(ab1)) - check(ab1, _ab1) - - // ArrayBuilder - val abu1 = ArrayBuilder.make[Long] - val _abu1: ArrayBuilder[ClassManifest[Long]] = read(write(abu1)) - check(abu1, _abu1) - - val abu2 = ArrayBuilder.make[Float] - val _abu2: ArrayBuilder[ClassManifest[Float]] = read(write(abu2)) - check(abu2, _abu2) - - // ArraySeq - val aq1 = ArraySeq(1, 2, 3) - val _aq1: ArraySeq[Int] = read(write(aq1)) - check(aq1, _aq1) - - // ArrayStack - val as1 = new ArrayStack[Int] - as1 ++= List(20, 2, 3).iterator - val _as1: ArrayStack[Int] = read(write(as1)) - check(as1, _as1) - - // BitSet - val bs1 = new BitSet() - bs1 += 0 - bs1 += 8 - bs1 += 9 - val _bs1: BitSet = read(write(bs1)) - check(bs1, _bs1) -/* - // DoubleLinkedList - val dl1 = new DoubleLinkedList[Int](2, null) - dl1.append(new DoubleLinkedList(3, null)) - val _dl1: DoubleLinkedList[Int] = read(write(dl1)) - check(dl1, _dl1) -*/ - // HashMap - val hm1 = new HashMap[String, Int] - hm1 ++= List(("A", 1), ("B", 2), ("C", 3)).iterator - val _hm1: HashMap[String, Int] = read(write(hm1)) - check(hm1, _hm1) - - // HashSet - val hs1 = new HashSet[String] - hs1 ++= List("layers", "buffers", "title").iterator - val _hs1: HashSet[String] = read(write(hs1)) - check(hs1, _hs1) - - val h1 = new History[String, Int] - val _h1: History[String, Int] = read(write(h1)) - check(h1, _h1) -/* - // LinkedList - val ll1 = new LinkedList[Int](2, null) - ll1.append(new LinkedList(3, null)) - val _ll1: LinkedList[Int] = read(write(ll1)) - check(ll1, _ll1) -*/ - // ListBuffer - val lb1 = new ListBuffer[String] - lb1 ++= List("white", "black") - val _lb1: ListBuffer[String] = read(write(lb1)) - check(lb1, _lb1) - - // Queue - val q1 = new Queue[Int] - q1 ++= List(20, 2, 3).iterator - val _q1: Queue[Int] = read(write(q1)) - check(q1, _q1) - - // Stack - val s1 = new Stack[Int] - s1 pushAll q1 - val _s1: Stack[Int] = read(write(s1)) - check(s1, _s1) - - // StringBuilder - val sb1 = new StringBuilder - sb1 append "abc" - val _sb1: StringBuilder = read(write(sb1)) - check(sb1, _sb1) - - // WrappedArray - val wa1 = WrappedArray.make(Array(1, 2, 3)) - val _wa1: WrappedArray[Int] = read(write(wa1)) - check(wa1, _wa1) - - // TreeSet - val ts1 = TreeSet[Int]() ++= Array(1, 2, 3) - val _ts1: TreeSet[Int] = read(write(ts1)) - check(ts1, _ts1) - - // concurrent.TrieMap - val ct1 = TrieMap[Int, String]() ++= Array(1 -> "one", 2 -> "two", 3 -> "three") - val _ct1: TrieMap[Int, String] = read(write(ct1)) - check(ct1, _ct1) - } - catch { - case e: Exception => - println("Error in Test3_mutable: " + e) - throw e - } -} - - -//############################################################################ -// Test classes in package "scala.xml" - -object Test4_xml { - import scala.xml.{Attribute, Document, Elem, Null, PrefixedAttribute, Text} - - case class Person(name: String, age: Int) - - try { - // Attribute - val a1 = new PrefixedAttribute("xml", "src", Text("hello"), Null) - val _a1: Attribute = read(write(a1)) - check(a1, _a1) - - // Document - val d1 = new Document - d1.docElem = - d1.encoding = Some("UTF-8") - val _d1: Document = read(write(d1)) - check(d1, _d1) - - // Elem - val e1 = title; - val _e1: Elem = read(write(e1)) - check(e1, _e1) - - class AddressBook(a: Person*) { - private val people: List[Person] = a.toList - def toXHTML = - - - - - - { for (p <- people) yield - - - - } -
Last NameFirst Name
{ p.name } { p.age.toString() }
; - } - - val people = new AddressBook( - Person("Tom", 20), - Person("Bob", 22), - Person("James", 19)) - - val e2 = - - - { people.toXHTML } - - ; - val _e2: Elem = read(write(e2)) - check(e2, _e2) - } - catch { - case e: Exception => - println("Error in Test4_xml: " + e) - throw e - } -} - -//############################################################################ -// Test user-defined classes WITHOUT nesting - -class Person(_name: String) extends Serializable { - private var name = _name - override def toString() = name - override def equals(that: Any): Boolean = - that.isInstanceOf[Person] && - (name == that.asInstanceOf[Person].name) -} - -class Employee(_name: String) extends Serializable { - private var name = _name - override def toString() = name -} - -object bob extends Employee("Bob") - -object Test5 { - val x1 = new Person("Tim") - val x2 = bob - - try { - val y1: Person = read(write(x1)) - val y2: Employee = read(write(x2)) - - check(x1, y1) - check(x2, y2) - } - catch { - case e: Exception => - println("Error in Test5: " + e) - } -} - -//############################################################################ -// Test user-defined classes WITH nesting - -object Test6 { - object bill extends Employee("Bill") { - val x = paul - } - object paul extends Person("Paul") { - val x = 4 // bill; => StackOverflowException !!! - } - val x1 = new Person("John") - val x2 = bill - val x3 = paul - - try { - val y1: Person = read(write(x1)) - val y2: Employee = read(write(x2)) - val y3: Person = read(write(x3)) - - check(x1, y1) - check(x2, y2) - check(x3, y3) - } - catch { - case e: Exception => - println("Error in Test6: " + e) - } -} - -//############################################################################ -// Nested objects cannot get readresolve automatically because after deserialization -// they would be null (they are treated as lazy vals) -class Outer extends Serializable { - object Inner extends Serializable -} - -object Test7 { - val x = new Outer - x.Inner // initialize - val y:Outer = read(write(x)) - if (y.Inner == null) - println("Inner object is null") -} - -// Verify that transient lazy vals don't get serialized -class WithTransient extends Serializable { - @transient lazy val a1 = 1 - @transient private lazy val a2 = 2 - @transient object B extends Serializable - @transient private object C extends Serializable - - def test = { - println(a1) - println(a2) - if (B == null || C == null) - println("Transient nested object failed to serialize properly") - } -} - -object Test8 { - val x = new WithTransient - x.test - try { - val y:WithTransient = read(write(x)) - y.test - } - catch { - case e: Exception => - println("Error in Test8: " + e) - } -} - -//############################################################################ -// Test code - -object Test { - def main(args: Array[String]) { - Test1_scala - Test2_immutable - Test3_mutable - Test4_xml - Test5 - Test6 - Test7 - Test8 - Test9_parallel - } -} - -//############################################################################ - - -//############################################################################ -// Test classes in package "scala.collection.parallel" and subpackages -object Test9_parallel { - import scala.collection.parallel._ - - try { - println() - - // UnrolledBuffer - val ub = new collection.mutable.UnrolledBuffer[String] - ub ++= List("one", "two") - val _ub: collection.mutable.UnrolledBuffer[String] = read(write(ub)) - check(ub, _ub) - - // mutable.ParArray - val pa = mutable.ParArray("abc", "def", "etc") - val _pa: mutable.ParArray[String] = read(write(pa)) - check(pa, _pa) - - // mutable.ParHashMap - val mpm = mutable.ParHashMap(1 -> 2, 2 -> 4) - val _mpm: mutable.ParHashMap[Int, Int] = read(write(mpm)) - check(mpm, _mpm) - - // mutable.ParTrieMap - val mpc = mutable.ParTrieMap(1 -> 2, 2 -> 4) - val _mpc: mutable.ParTrieMap[Int, Int] = read(write(mpc)) - check(mpc, _mpc) - - // mutable.ParHashSet - val mps = mutable.ParHashSet(1, 2, 3) - val _mps: mutable.ParHashSet[Int] = read(write(mps)) - check(mps, _mps) - - // immutable.ParRange - val pr1 = immutable.ParRange(0, 4, 1, true) - val _pr1: immutable.ParRange = read(write(pr1)) - check(pr1, _pr1) - - val pr2 = immutable.ParRange(0, 4, 1, false) - val _pr2: immutable.ParRange = read(write(pr2)) - check(pr2, _pr2) - - // immutable.ParHashMap - val ipm = immutable.ParHashMap(5 -> 1, 10 -> 2) - val _ipm: immutable.ParHashMap[Int, Int] = read(write(ipm)) - check(ipm, _ipm) - - // immutable.ParHashSet - val ips = immutable.ParHashSet("one", "two") - val _ips: immutable.ParHashSet[String] = read(write(ips)) - check(ips, _ips) - - } catch { - case e: Exception => - println("Error in Test5_parallel: " + e) - throw e - } -} diff --git a/test/files/neg/t2386.check b/test/files/neg/t2386.check deleted file mode 100644 index f70f12535f..0000000000 --- a/test/files/neg/t2386.check +++ /dev/null @@ -1,4 +0,0 @@ -t2386.scala:2: error: No ClassTag available for Array[_ >: String with Int] - val a = Array(Array(1, 2), Array("a","b")) - ^ -one error found diff --git a/test/files/neg/t2386.scala b/test/files/neg/t2386.scala deleted file mode 100644 index 56146cc5c3..0000000000 --- a/test/files/neg/t2386.scala +++ /dev/null @@ -1,3 +0,0 @@ -object Test { - val a = Array(Array(1, 2), Array("a","b")) -} diff --git a/test/files/neg/t3692-new.check b/test/files/neg/t3692-new.check new file mode 100644 index 0000000000..e013daca74 --- /dev/null +++ b/test/files/neg/t3692-new.check @@ -0,0 +1,4 @@ +t3692-new.scala:15: error: unreachable code + case m2: Map[T, Int] => new java.util.HashMap[T, Integer] + ^ +one error found diff --git a/test/files/neg/t3692-new.flags b/test/files/neg/t3692-new.flags new file mode 100644 index 0000000000..82becdfbfd --- /dev/null +++ b/test/files/neg/t3692-new.flags @@ -0,0 +1 @@ + -Xoldpatmat \ No newline at end of file diff --git a/test/files/neg/t3692-new.scala b/test/files/neg/t3692-new.scala new file mode 100644 index 0000000000..46874b02e3 --- /dev/null +++ b/test/files/neg/t3692-new.scala @@ -0,0 +1,19 @@ +import java.lang.Integer + +object Tester { + def main(args: Array[String]) = { + val map = Map("John" -> 1, "Josh" -> 2) + new Tester().toJavaMap(map) + } +} + +class Tester { + private final def toJavaMap[T, V](map: Map[T, V])(implicit m1: ClassTag[T], m2: ClassTag[V]): java.util.Map[_, _] = { + map match { + case m0: Map[Int, Int] => new java.util.HashMap[Integer, Integer] + case m1: Map[Int, V] => new java.util.HashMap[Integer, V] + case m2: Map[T, Int] => new java.util.HashMap[T, Integer] + case _ => new java.util.HashMap[T, V] + } + } +} \ No newline at end of file diff --git a/test/files/neg/t3692.check b/test/files/neg/t3692.check deleted file mode 100644 index d83abd31e2..0000000000 --- a/test/files/neg/t3692.check +++ /dev/null @@ -1,11 +0,0 @@ -t3692.scala:11: warning: type Manifest in object Predef is deprecated: Use `@scala.reflect.ConcreteTypeTag` instead - private final def toJavaMap[T, V](map: Map[T, V])(implicit m1: Manifest[T], m2: Manifest[V]): java.util.Map[_, _] = { - ^ -t3692.scala:11: warning: type Manifest in object Predef is deprecated: Use `@scala.reflect.ConcreteTypeTag` instead - private final def toJavaMap[T, V](map: Map[T, V])(implicit m1: Manifest[T], m2: Manifest[V]): java.util.Map[_, _] = { - ^ -t3692.scala:15: error: unreachable code - case m2: Map[T, Int] => new java.util.HashMap[T, Integer] - ^ -two warnings found -one error found diff --git a/test/files/neg/t3692.flags b/test/files/neg/t3692.flags deleted file mode 100644 index 82becdfbfd..0000000000 --- a/test/files/neg/t3692.flags +++ /dev/null @@ -1 +0,0 @@ - -Xoldpatmat \ No newline at end of file diff --git a/test/files/neg/t3692.scala b/test/files/neg/t3692.scala deleted file mode 100644 index 151535ae94..0000000000 --- a/test/files/neg/t3692.scala +++ /dev/null @@ -1,19 +0,0 @@ -import java.lang.Integer - -object ManifestTester { - def main(args: Array[String]) = { - val map = Map("John" -> 1, "Josh" -> 2) - new ManifestTester().toJavaMap(map) - } -} - -class ManifestTester { - private final def toJavaMap[T, V](map: Map[T, V])(implicit m1: Manifest[T], m2: Manifest[V]): java.util.Map[_, _] = { - map match { - case m0: Map[Int, Int] => new java.util.HashMap[Integer, Integer] - case m1: Map[Int, V] => new java.util.HashMap[Integer, V] - case m2: Map[T, Int] => new java.util.HashMap[T, Integer] - case _ => new java.util.HashMap[T, V] - } - } -} \ No newline at end of file diff --git a/test/files/neg/t5452-new.check b/test/files/neg/t5452-new.check new file mode 100644 index 0000000000..bbd3734f74 --- /dev/null +++ b/test/files/neg/t5452-new.check @@ -0,0 +1,8 @@ +t5452-new.scala:28: error: overloaded method value apply with alternatives: + ()Queryable[CoffeesTable] + (t: Tree)(implicit evidence$2: ClassTag[CoffeesTable])Nothing + (implicit evidence$1: ClassTag[CoffeesTable])Nothing + cannot be applied to (Queryable[CoffeesTable]) + Queryable[CoffeesTable]( q.treeFilter(null) ) + ^ +one error found diff --git a/test/files/neg/t5452-new.scala b/test/files/neg/t5452-new.scala new file mode 100644 index 0000000000..c829de7d7c --- /dev/null +++ b/test/files/neg/t5452-new.scala @@ -0,0 +1,29 @@ +// /scala/trac/5452/a.scala +// Mon Feb 13 22:52:36 PST 2012 + +// import scala.reflect.mirror._ + +trait Tree + +object Bip { + def ??? = sys.error("") +} +import Bip._ + +case class Queryable[T]() { + def treeFilter( t:Tree ) : Queryable[T] = ??? +} + +object Queryable { + def apply[T:ClassTag] = ??? + def apply[T:ClassTag]( t:Tree ) = ??? +} + +trait CoffeesTable{ + def sales : Int +} + +object Test extends App{ + val q = new Queryable[CoffeesTable] + Queryable[CoffeesTable]( q.treeFilter(null) ) +} diff --git a/test/files/neg/t5452.check b/test/files/neg/t5452.check deleted file mode 100644 index 2f35a45509..0000000000 --- a/test/files/neg/t5452.check +++ /dev/null @@ -1,8 +0,0 @@ -t5452.scala:28: error: overloaded method value apply with alternatives: - ()Queryable[CoffeesTable] - (t: Tree)(implicit evidence$2: Manifest[CoffeesTable])Nothing - (implicit evidence$1: Manifest[CoffeesTable])Nothing - cannot be applied to (Queryable[CoffeesTable]) - Queryable[CoffeesTable]( q.treeFilter(null) ) - ^ -one error found diff --git a/test/files/neg/t5452.scala b/test/files/neg/t5452.scala deleted file mode 100644 index 1032db7a4b..0000000000 --- a/test/files/neg/t5452.scala +++ /dev/null @@ -1,29 +0,0 @@ -// /scala/trac/5452/a.scala -// Mon Feb 13 22:52:36 PST 2012 - -// import scala.reflect.mirror._ - -trait Tree - -object Bip { - def ??? = sys.error("") -} -import Bip._ - -case class Queryable[T]() { - def treeFilter( t:Tree ) : Queryable[T] = ??? -} - -object Queryable { - def apply[T:Manifest] = ??? - def apply[T:Manifest]( t:Tree ) = ??? -} - -trait CoffeesTable{ - def sales : Int -} - -object Test extends App{ - val q = new Queryable[CoffeesTable] - Queryable[CoffeesTable]( q.treeFilter(null) ) -} diff --git a/test/files/pos/contextbounds-implicits-new.scala b/test/files/pos/contextbounds-implicits-new.scala new file mode 100644 index 0000000000..71b3cca36f --- /dev/null +++ b/test/files/pos/contextbounds-implicits-new.scala @@ -0,0 +1,8 @@ +/* Tests implicit parameters in the presence of context bounds. + * See Section 7.4 of the Scala Language Specification. + */ +class C { + + def f[T: TypeTag, S: TypeTag](x: T, y: S)(implicit p: C) { } + +} diff --git a/test/files/pos/contextbounds-implicits.scala b/test/files/pos/contextbounds-implicits.scala deleted file mode 100644 index f9113ee320..0000000000 --- a/test/files/pos/contextbounds-implicits.scala +++ /dev/null @@ -1,8 +0,0 @@ -/* Tests implicit parameters in the presence of context bounds. - * See Section 7.4 of the Scala Language Specification. - */ -class C { - - def f[T: Manifest, S: Manifest](x: T, y: S)(implicit p: C) { } - -} diff --git a/test/files/pos/implicits-new.scala b/test/files/pos/implicits-new.scala new file mode 100644 index 0000000000..7eb7e100c3 --- /dev/null +++ b/test/files/pos/implicits-new.scala @@ -0,0 +1,89 @@ +// #1435 +object t1435 { + implicit def a(s:String):String = error("") + implicit def a(i:Int):String = error("") + implicit def b(i:Int):String = error("") +} + +class C1435 { + val v:String = { + import t1435.a + 2 + } +} + +// #1492 +class C1492 { + + class X + + def foo(x: X => X) {} + + foo ( implicit x => implicitly[X] ) + foo { implicit x => implicitly[X] } +} + +// #1579 +object Test1579 { + class Column + class Query[E](val value: E) + class Invoker(q: Any) { val foo = null } + + implicit def unwrap[C](q: Query[C]) = q.value + implicit def invoker(q: Query[Column]) = new Invoker(q) + + val q = new Query(new Column) + q.foo +} +// #1625 +object Test1625 { + + class Wrapped(x:Any) { + def unwrap() = x + } + + implicit def byName[A](x: =>A) = new Wrapped(x) + + implicit def byVal[A](x: A) = x + + def main(args: Array[String]) = { + +// val res:Wrapped = 7 // works + + val res = 7.unwrap() // doesn't work + + println("=> result: " + res) + } +} + +object Test2188 { + implicit def toJavaList[A: ArrayTag](t:collection.Seq[A]):java.util.List[A] = java.util.Arrays.asList(t.toArray:_*) + + val x: java.util.List[String] = List("foo") +} + +object TestNumericWidening { + val y = 1 + val x: java.lang.Long = y +} + +// #2709 +package foo2709 { + class A + class B + + package object bar { + implicit def a2b(a: A): B = new B + } + + package bar { + object test { + new A: B + } + } +} + +// Problem with specs +object specsProblem { + println(implicitly[ConcreteTypeTag[Class[_]]]) +} diff --git a/test/files/pos/implicits.scala b/test/files/pos/implicits.scala deleted file mode 100644 index 2c01dd0ba8..0000000000 --- a/test/files/pos/implicits.scala +++ /dev/null @@ -1,89 +0,0 @@ -// #1435 -object t1435 { - implicit def a(s:String):String = error("") - implicit def a(i:Int):String = error("") - implicit def b(i:Int):String = error("") -} - -class C1435 { - val v:String = { - import t1435.a - 2 - } -} - -// #1492 -class C1492 { - - class X - - def foo(x: X => X) {} - - foo ( implicit x => implicitly[X] ) - foo { implicit x => implicitly[X] } -} - -// #1579 -object Test1579 { - class Column - class Query[E](val value: E) - class Invoker(q: Any) { val foo = null } - - implicit def unwrap[C](q: Query[C]) = q.value - implicit def invoker(q: Query[Column]) = new Invoker(q) - - val q = new Query(new Column) - q.foo -} -// #1625 -object Test1625 { - - class Wrapped(x:Any) { - def unwrap() = x - } - - implicit def byName[A](x: =>A) = new Wrapped(x) - - implicit def byVal[A](x: A) = x - - def main(args: Array[String]) = { - -// val res:Wrapped = 7 // works - - val res = 7.unwrap() // doesn't work - - println("=> result: " + res) - } -} - -object Test2188 { - implicit def toJavaList[A: ClassManifest](t:collection.Seq[A]):java.util.List[A] = java.util.Arrays.asList(t.toArray:_*) - - val x: java.util.List[String] = List("foo") -} - -object TestNumericWidening { - val y = 1 - val x: java.lang.Long = y -} - -// #2709 -package foo2709 { - class A - class B - - package object bar { - implicit def a2b(a: A): B = new B - } - - package bar { - object test { - new A: B - } - } -} - -// Problem with specs -object specsProblem { - println(implicitly[Manifest[Class[_]]]) -} diff --git a/test/files/pos/manifest1-new.scala b/test/files/pos/manifest1-new.scala new file mode 100644 index 0000000000..645bd42665 --- /dev/null +++ b/test/files/pos/manifest1-new.scala @@ -0,0 +1,21 @@ +import scala.reflect.TypeTag + +object Test { + def foo[T](x: T)(implicit m: TypeTag[T]) { + foo(List(x)) + } + foo(1) + foo("abc") + foo(List(1, 2, 3)) + val x: List[Int] with Ordered[List[Int]] = null + foo(x) + foo[x.type](x) + abstract class C { type T = String; val x: T } + val c = new C { val x = "abc" } + foo(c.x) + abstract class D { type T; implicit val m: TypeTag[T]; val x: T } + val stringm = implicitly[TypeTag[String]] + val d: D = new D { type T = String; val m = stringm; val x = "x" } + import d.m + foo(d.x) +} diff --git a/test/files/pos/manifest1.scala b/test/files/pos/manifest1.scala deleted file mode 100644 index 8901aa7437..0000000000 --- a/test/files/pos/manifest1.scala +++ /dev/null @@ -1,21 +0,0 @@ -import scala.reflect.Manifest - -object Test { - def foo[T](x: T)(implicit m: Manifest[T]) { - foo(List(x)) - } - foo(1) - foo("abc") - foo(List(1, 2, 3)) - val x: List[Int] with Ordered[List[Int]] = null - foo(x) - foo[x.type](x) - abstract class C { type T = String; val x: T } - val c = new C { val x = "abc" } - foo(c.x) - abstract class D { type T; implicit val m: Manifest[T]; val x: T } - val stringm = implicitly[Manifest[String]] - val d: D = new D { type T = String; val m = stringm; val x = "x" } - import d.m - foo(d.x) -} diff --git a/test/files/pos/nothing_manifest_disambig-new.scala b/test/files/pos/nothing_manifest_disambig-new.scala new file mode 100644 index 0000000000..a60b0fdbf8 --- /dev/null +++ b/test/files/pos/nothing_manifest_disambig-new.scala @@ -0,0 +1,10 @@ +object Test { + def mani[T: TypeTag](xs: T) = xs + mani(List()) + + def listElMani[T: TypeTag](xs: List[T]) = xs + listElMani(List()) + + def foo[A, C](m : C)(implicit ev: C <:< Traversable[A], mani: TypeTag[A]): (C, A, TypeTag[A]) = (m, m.head, mani) + foo(List(1,2,3)) +} \ No newline at end of file diff --git a/test/files/pos/nothing_manifest_disambig.scala b/test/files/pos/nothing_manifest_disambig.scala deleted file mode 100644 index 076742033f..0000000000 --- a/test/files/pos/nothing_manifest_disambig.scala +++ /dev/null @@ -1,10 +0,0 @@ -object Test { - def mani[T: Manifest](xs: T) = xs - mani(List()) - - def listElMani[T: Manifest](xs: List[T]) = xs - listElMani(List()) - - def foo[A, C](m : C)(implicit ev: C <:< Traversable[A], mani: Manifest[A]): (C, A, Manifest[A]) = (m, m.head, mani) - foo(List(1,2,3)) -} \ No newline at end of file diff --git a/test/files/pos/spec-constr-new.scala b/test/files/pos/spec-constr-new.scala new file mode 100644 index 0000000000..7cd02b0680 --- /dev/null +++ b/test/files/pos/spec-constr-new.scala @@ -0,0 +1,7 @@ +class SparseArray2[@specialized(Int) T:ArrayTag](val maxSize: Int, initialLength:Int = 3) { + private var data = new Array[T](initialLength); + private var index = new Array[Int](initialLength); + + // comment out to compile correctly + data.length + 3; +} diff --git a/test/files/pos/spec-constr.scala b/test/files/pos/spec-constr.scala deleted file mode 100644 index e908b65a41..0000000000 --- a/test/files/pos/spec-constr.scala +++ /dev/null @@ -1,7 +0,0 @@ -class SparseArray2[@specialized(Int) T:ClassManifest](val maxSize: Int, initialLength:Int = 3) { - private var data = new Array[T](initialLength); - private var index = new Array[Int](initialLength); - - // comment out to compile correctly - data.length + 3; -} diff --git a/test/files/pos/spec-doubledef-new.scala b/test/files/pos/spec-doubledef-new.scala new file mode 100644 index 0000000000..33f1e82b6e --- /dev/null +++ b/test/files/pos/spec-doubledef-new.scala @@ -0,0 +1,28 @@ +object Test { + def fn[@specialized T, @specialized U](t : T => Int, u : U => Int) : T = + null.asInstanceOf[T] +} + +trait A[@specialized(Int) T] { + var value: T + def getWith[@specialized(Int) Z](f: T => Z) = f(value) +} + +class C extends A[Int] { + var value = 10 + override def getWith[@specialized(Int) Z](f: Int => Z) = f(value) +} + +abstract class B[T, @specialized(scala.Int) U : TypeTag, @specialized(scala.Int) V <% Ordered[V]] { + val u: U + val v: V + + def f(t: T, v2: V): Pair[U, V] = { + val m: Array[U] = null + if (m.isEmpty) { + Pair(u, v) + } else { + Pair(u, v2) + } + } +} diff --git a/test/files/pos/spec-doubledef.scala b/test/files/pos/spec-doubledef.scala deleted file mode 100644 index 86b0d857d3..0000000000 --- a/test/files/pos/spec-doubledef.scala +++ /dev/null @@ -1,28 +0,0 @@ -object Test { - def fn[@specialized T, @specialized U](t : T => Int, u : U => Int) : T = - null.asInstanceOf[T] -} - -trait A[@specialized(Int) T] { - var value: T - def getWith[@specialized(Int) Z](f: T => Z) = f(value) -} - -class C extends A[Int] { - var value = 10 - override def getWith[@specialized(Int) Z](f: Int => Z) = f(value) -} - -abstract class B[T, @specialized(scala.Int) U : Manifest, @specialized(scala.Int) V <% Ordered[V]] { - val u: U - val v: V - - def f(t: T, v2: V): Pair[U, V] = { - val m: Array[U] = null - if (m.isEmpty) { - Pair(u, v) - } else { - Pair(u, v2) - } - } -} diff --git a/test/files/pos/spec-fields-new.scala b/test/files/pos/spec-fields-new.scala new file mode 100644 index 0000000000..ddd8bd6624 --- /dev/null +++ b/test/files/pos/spec-fields-new.scala @@ -0,0 +1,10 @@ +abstract class Foo[@specialized T: ArrayTag, U <: Ordered[U]](x: T, size: Int) { + var y: T + var z: T = x + + def initialSize = 16 + val array = new Array[T](initialSize + size) + + def getZ = z + def setZ(zz: T) = z = zz +} diff --git a/test/files/pos/spec-fields.scala b/test/files/pos/spec-fields.scala deleted file mode 100644 index 26a8c4ffbd..0000000000 --- a/test/files/pos/spec-fields.scala +++ /dev/null @@ -1,10 +0,0 @@ -abstract class Foo[@specialized T: ClassManifest, U <: Ordered[U]](x: T, size: Int) { - var y: T - var z: T = x - - def initialSize = 16 - val array = new Array[T](initialSize + size) - - def getZ = z - def setZ(zz: T) = z = zz -} diff --git a/test/files/pos/spec-params-new.scala b/test/files/pos/spec-params-new.scala new file mode 100644 index 0000000000..5fe0c82d40 --- /dev/null +++ b/test/files/pos/spec-params-new.scala @@ -0,0 +1,32 @@ +class Foo[@specialized A: ArrayTag] { + + // conflicting in bounds, expect a normalized member calling m + // and bridge + implementation in specialized subclasses + // and overloads here according to specialization on A + def m1[@specialized B <: A](x: B, y: A) = + goal(x) + + // conflicting, unsolvable, expect a warning + def m2[@specialized B <: String](x: B) = x.concat("a") + + // conflicting in bounds, no mention of other spec members + // expect an overload here plus implementation in + // compatible specialized subclasses + def m3[@specialized B >: A](x: B) = () + + // non-conflicting, expect a normalized overload implementation here + def m4[@specialized T, U <: Ordered[T]](x: T, y: U) = () + + // non-conflicting, expect a normalized overload implementation here + def m5[@specialized B](x: B) = x + + // non-conflicting, expect a normalized implementation here + // and specialized implementations for all expansions in specialized subclasses + def m6[@specialized B](x: B, y: A) = + goal(y) + + def goal(x: A) = { + val xs = new Array[A](1) + xs(0) = x + } +} diff --git a/test/files/pos/spec-params.scala b/test/files/pos/spec-params.scala deleted file mode 100644 index f522512846..0000000000 --- a/test/files/pos/spec-params.scala +++ /dev/null @@ -1,32 +0,0 @@ -class Foo[@specialized A: ClassManifest] { - - // conflicting in bounds, expect a normalized member calling m - // and bridge + implementation in specialized subclasses - // and overloads here according to specialization on A - def m1[@specialized B <: A](x: B, y: A) = - goal(x) - - // conflicting, unsolvable, expect a warning - def m2[@specialized B <: String](x: B) = x.concat("a") - - // conflicting in bounds, no mention of other spec members - // expect an overload here plus implementation in - // compatible specialized subclasses - def m3[@specialized B >: A](x: B) = () - - // non-conflicting, expect a normalized overload implementation here - def m4[@specialized T, U <: Ordered[T]](x: T, y: U) = () - - // non-conflicting, expect a normalized overload implementation here - def m5[@specialized B](x: B) = x - - // non-conflicting, expect a normalized implementation here - // and specialized implementations for all expansions in specialized subclasses - def m6[@specialized B](x: B, y: A) = - goal(y) - - def goal(x: A) = { - val xs = new Array[A](1) - xs(0) = x - } -} diff --git a/test/files/pos/spec-sparsearray-new.scala b/test/files/pos/spec-sparsearray-new.scala new file mode 100644 index 0000000000..0659bf7926 --- /dev/null +++ b/test/files/pos/spec-sparsearray-new.scala @@ -0,0 +1,24 @@ +import scala.collection.mutable.MapLike + +class SparseArray[@specialized(Int) T:ArrayTag] extends collection.mutable.Map[Int,T] with collection.mutable.MapLike[Int,T,SparseArray[T]] { + override def get(x: Int) = { + val ind = findOffset(x) + if(ind < 0) None else Some(error("ignore")) + } + + /** + * Returns the offset into index and data for the requested vector + * index. If the requested index is not found, the return value is + * negative and can be converted into an insertion point with -(rv+1). + */ + private def findOffset(i : Int) : Int = { + error("impl doesn't matter") + } + + override def apply(i : Int) : T = { error("ignore") } + override def update(i : Int, value : T) = error("ignore") + override def empty = new SparseArray[T] + def -=(ind: Int) = error("ignore") + def +=(kv: (Int,T)) = error("ignore") + override final def iterator = error("ignore") +} diff --git a/test/files/pos/spec-sparsearray.scala b/test/files/pos/spec-sparsearray.scala deleted file mode 100644 index ea7710a785..0000000000 --- a/test/files/pos/spec-sparsearray.scala +++ /dev/null @@ -1,24 +0,0 @@ -import scala.collection.mutable.MapLike - -class SparseArray[@specialized(Int) T:ClassManifest] extends collection.mutable.Map[Int,T] with collection.mutable.MapLike[Int,T,SparseArray[T]] { - override def get(x: Int) = { - val ind = findOffset(x) - if(ind < 0) None else Some(error("ignore")) - } - - /** - * Returns the offset into index and data for the requested vector - * index. If the requested index is not found, the return value is - * negative and can be converted into an insertion point with -(rv+1). - */ - private def findOffset(i : Int) : Int = { - error("impl doesn't matter") - } - - override def apply(i : Int) : T = { error("ignore") } - override def update(i : Int, value : T) = error("ignore") - override def empty = new SparseArray[T] - def -=(ind: Int) = error("ignore") - def +=(kv: (Int,T)) = error("ignore") - override final def iterator = error("ignore") -} diff --git a/test/files/pos/t1381-new.scala b/test/files/pos/t1381-new.scala new file mode 100644 index 0000000000..8781ef4fdb --- /dev/null +++ b/test/files/pos/t1381-new.scala @@ -0,0 +1,31 @@ +import scala.reflect.TypeTag + +class D[V <: Variable] + +class ID[V<:IV] extends D[V] { + type E = V#ValueType + def index(value:E) : Int = 0 + // Comment this out to eliminate crash. Or see below + def index(values:E*) : Iterable[Int] = null +} + +abstract class Variable { + type VT <: Variable + def d : D[VT] = null +} + +abstract class PV[T](initval:T) extends Variable { + type VT <: PV[T] + type ValueType = T +} + +trait IV extends Variable { + type ValueType +} + +abstract class EV[T](initval:T) extends PV[T](initval) with IV { + type VT <: EV[T] + override def d : ID[VT] = null + // Comment this out to eliminate crash + protected var indx = d.index(initval) +} diff --git a/test/files/pos/t1381.scala b/test/files/pos/t1381.scala deleted file mode 100644 index 0762891898..0000000000 --- a/test/files/pos/t1381.scala +++ /dev/null @@ -1,31 +0,0 @@ -import scala.reflect.Manifest - -class D[V <: Variable] - -class ID[V<:IV] extends D[V] { - type E = V#ValueType - def index(value:E) : Int = 0 - // Comment this out to eliminate crash. Or see below - def index(values:E*) : Iterable[Int] = null -} - -abstract class Variable { - type VT <: Variable - def d : D[VT] = null -} - -abstract class PV[T](initval:T) extends Variable { - type VT <: PV[T] - type ValueType = T -} - -trait IV extends Variable { - type ValueType -} - -abstract class EV[T](initval:T) extends PV[T](initval) with IV { - type VT <: EV[T] - override def d : ID[VT] = null - // Comment this out to eliminate crash - protected var indx = d.index(initval) -} diff --git a/test/files/pos/t2795-new.scala b/test/files/pos/t2795-new.scala new file mode 100644 index 0000000000..af9c4e8b1c --- /dev/null +++ b/test/files/pos/t2795-new.scala @@ -0,0 +1,17 @@ +package t1 + +trait Element[T] { +} + +trait Config { + type T <: Element[T] + implicit val m: ArrayTag[T] + // XXX Following works fine: + // type T <: Element[_] +} + +trait Transform { self: Config => + def processBlock(block: Array[T]): Unit = { + var X = new Array[T](1) + } +} diff --git a/test/files/pos/t2795.scala b/test/files/pos/t2795.scala deleted file mode 100644 index 935cb1f444..0000000000 --- a/test/files/pos/t2795.scala +++ /dev/null @@ -1,17 +0,0 @@ -package t1 - -trait Element[T] { -} - -trait Config { - type T <: Element[T] - implicit val m: ClassManifest[T] - // XXX Following works fine: - // type T <: Element[_] -} - -trait Transform { self: Config => - def processBlock(block: Array[T]): Unit = { - var X = new Array[T](1) - } -} diff --git a/test/files/pos/t3363-new.scala b/test/files/pos/t3363-new.scala new file mode 100644 index 0000000000..270462745c --- /dev/null +++ b/test/files/pos/t3363-new.scala @@ -0,0 +1,18 @@ +object TestCase { + + //now matter if you put (abstract) class or trait it will fail in all cases + trait MapOps[T] + + //if fs was reduced to List (generic type with one parameter) then the code compiles + //if you inherit from MapOps[T] instead of MapOps[F] then code compiles fine + implicit def map2ops[T,F](fs: Map[T,F]) = new MapOps[F] { + //if you remove this line, then code compiles + lazy val m: TypeTag[T] = error("just something to make it compile") + def is(xs: List[T]) = List(xs) + } + + def main(args: Array[String]) { + println(Map(1 -> "2") is List(2)) + } + + } diff --git a/test/files/pos/t3363.scala b/test/files/pos/t3363.scala deleted file mode 100755 index bae54084ea..0000000000 --- a/test/files/pos/t3363.scala +++ /dev/null @@ -1,18 +0,0 @@ -object TestCase { - - //now matter if you put (abstract) class or trait it will fail in all cases - trait MapOps[T] - - //if fs was reduced to List (generic type with one parameter) then the code compiles - //if you inherit from MapOps[T] instead of MapOps[F] then code compiles fine - implicit def map2ops[T,F](fs: Map[T,F]) = new MapOps[F] { - //if you remove this line, then code compiles - lazy val m: Manifest[T] = error("just something to make it compile") - def is(xs: List[T]) = List(xs) - } - - def main(args: Array[String]) { - println(Map(1 -> "2") is List(2)) - } - - } diff --git a/test/files/pos/t3498-new.scala b/test/files/pos/t3498-new.scala new file mode 100644 index 0000000000..653c50042a --- /dev/null +++ b/test/files/pos/t3498-new.scala @@ -0,0 +1,15 @@ +abstract class A[T, @specialized(scala.Int) U : ArrayTag] { + def f(state: T): Array[U] +} + +abstract class B extends A[ Array[Byte], Int ] { + type T = Array[Byte] + type U = Int + + val N = 0 + + def f(state: T): Array[U] = + { + new Array[U](N + state(N)) + } +} \ No newline at end of file diff --git a/test/files/pos/t3498.scala b/test/files/pos/t3498.scala deleted file mode 100644 index bcc90ca64c..0000000000 --- a/test/files/pos/t3498.scala +++ /dev/null @@ -1,15 +0,0 @@ -abstract class A[T, @specialized(scala.Int) U : Manifest] { - def f(state: T): Array[U] -} - -abstract class B extends A[ Array[Byte], Int ] { - type T = Array[Byte] - type U = Int - - val N = 0 - - def f(state: T): Array[U] = - { - new Array[U](N + state(N)) - } -} \ No newline at end of file diff --git a/test/files/presentation/ide-bug-1000531.check b/test/files/presentation/ide-bug-1000531.check index ae202001eb..2b48a80d38 100644 --- a/test/files/presentation/ide-bug-1000531.check +++ b/test/files/presentation/ide-bug-1000531.check @@ -99,7 +99,7 @@ retrieved 123 members `method synchronized[T0](x$1: T0)T0` `method take(n: Int)Iterator[B]` `method takeWhile(p: B => Boolean)Iterator[B]` -`method toArray[B >: B](implicit evidence$1: ClassManifest[B])Array[B]` +`method toArray[B >: B](implicit evidence$1: ArrayTag[B])Array[B]` `method toBuffer[B >: B]=> scala.collection.mutable.Buffer[B]` `method toIndexedSeq=> scala.collection.immutable.IndexedSeq[B]` `method toIterable=> Iterable[B]` diff --git a/test/files/run/arrayclone-new.scala b/test/files/run/arrayclone-new.scala new file mode 100644 index 0000000000..a4ba021409 --- /dev/null +++ b/test/files/run/arrayclone-new.scala @@ -0,0 +1,106 @@ +object Test extends App{ + BooleanArrayClone; + ByteArrayClone; + ShortArrayClone; + CharArrayClone; + IntArrayClone; + LongArrayClone; + FloatArrayClone; + DoubleArrayClone; + ObjectArrayClone; + PolymorphicArrayClone; +} + +object BooleanArrayClone{ + val it : Array[Boolean] = Array(true, false); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = false; + assert(it(0) == true) +} + +object ByteArrayClone{ + val it : Array[Byte] = Array(1, 0); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = 0; + assert(it(0) == 1) +} + +object ShortArrayClone{ + val it : Array[Short] = Array(1, 0); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = 0; + assert(it(0) == 1) +} + +object CharArrayClone{ + val it : Array[Char] = Array(1, 0); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = 0; + assert(it(0) == 1) +} + +object IntArrayClone{ + val it : Array[Int] = Array(1, 0); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = 0; + assert(it(0) == 1) +} + +object LongArrayClone{ + val it : Array[Long] = Array(1, 0); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = 0; + assert(it(0) == 1) +} + +object FloatArrayClone{ + val it : Array[Float] = Array(1, 0); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = 0; + assert(it(0) == 1) +} + +object DoubleArrayClone{ + val it : Array[Double] = Array(1, 0); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = 0; + assert(it(0) == 1) +} + +object ObjectArrayClone{ + val it : Array[String] = Array("1", "0"); + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = "0"; + assert(it(0) == "1") +} + +object PolymorphicArrayClone{ + def testIt[T](it : Array[T], one : T, zero : T) = { + val cloned = it.clone(); + assert(cloned.sameElements(it)); + cloned(0) = zero; + assert(it(0) == one) + } + + testIt(Array("one", "two"), "one", "two"); + + class Mangler[T: ArrayTag](ts : T*){ + // this will always be a BoxedAnyArray even after we've unboxed its contents. + val it = ts.toArray[T]; + } + + val mangled = new Mangler[Int](0, 1); + + val y : Array[Int] = mangled.it; // make sure it's unboxed + + testIt(mangled.it, 0, 1); +} diff --git a/test/files/run/arrayclone.scala b/test/files/run/arrayclone.scala deleted file mode 100644 index c9f7556b47..0000000000 --- a/test/files/run/arrayclone.scala +++ /dev/null @@ -1,106 +0,0 @@ -object Test extends App{ - BooleanArrayClone; - ByteArrayClone; - ShortArrayClone; - CharArrayClone; - IntArrayClone; - LongArrayClone; - FloatArrayClone; - DoubleArrayClone; - ObjectArrayClone; - PolymorphicArrayClone; -} - -object BooleanArrayClone{ - val it : Array[Boolean] = Array(true, false); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = false; - assert(it(0) == true) -} - -object ByteArrayClone{ - val it : Array[Byte] = Array(1, 0); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = 0; - assert(it(0) == 1) -} - -object ShortArrayClone{ - val it : Array[Short] = Array(1, 0); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = 0; - assert(it(0) == 1) -} - -object CharArrayClone{ - val it : Array[Char] = Array(1, 0); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = 0; - assert(it(0) == 1) -} - -object IntArrayClone{ - val it : Array[Int] = Array(1, 0); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = 0; - assert(it(0) == 1) -} - -object LongArrayClone{ - val it : Array[Long] = Array(1, 0); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = 0; - assert(it(0) == 1) -} - -object FloatArrayClone{ - val it : Array[Float] = Array(1, 0); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = 0; - assert(it(0) == 1) -} - -object DoubleArrayClone{ - val it : Array[Double] = Array(1, 0); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = 0; - assert(it(0) == 1) -} - -object ObjectArrayClone{ - val it : Array[String] = Array("1", "0"); - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = "0"; - assert(it(0) == "1") -} - -object PolymorphicArrayClone{ - def testIt[T](it : Array[T], one : T, zero : T) = { - val cloned = it.clone(); - assert(cloned.sameElements(it)); - cloned(0) = zero; - assert(it(0) == one) - } - - testIt(Array("one", "two"), "one", "two"); - - class Mangler[T: Manifest](ts : T*){ - // this will always be a BoxedAnyArray even after we've unboxed its contents. - val it = ts.toArray[T]; - } - - val mangled = new Mangler[Int](0, 1); - - val y : Array[Int] = mangled.it; // make sure it's unboxed - - testIt(mangled.it, 0, 1); -} diff --git a/test/files/run/ctries-new/DumbHash.scala b/test/files/run/ctries-new/DumbHash.scala new file mode 100644 index 0000000000..8ef325b67c --- /dev/null +++ b/test/files/run/ctries-new/DumbHash.scala @@ -0,0 +1,14 @@ + + + + + + +class DumbHash(val i: Int) { + override def equals(other: Any) = other match { + case that: DumbHash => that.i == this.i + case _ => false + } + override def hashCode = i % 5 + override def toString = "DH(%s)".format(i) +} diff --git a/test/files/run/ctries-new/Wrap.scala b/test/files/run/ctries-new/Wrap.scala new file mode 100644 index 0000000000..7b645c1612 --- /dev/null +++ b/test/files/run/ctries-new/Wrap.scala @@ -0,0 +1,9 @@ + + + + + + +case class Wrap(i: Int) { + override def hashCode = i * 0x9e3775cd +} diff --git a/test/files/run/ctries-new/concmap.scala b/test/files/run/ctries-new/concmap.scala new file mode 100644 index 0000000000..3ec0256afb --- /dev/null +++ b/test/files/run/ctries-new/concmap.scala @@ -0,0 +1,188 @@ + + + +import collection.concurrent.TrieMap + + +object ConcurrentMapSpec extends Spec { + + val initsz = 500 + val secondsz = 750 + + def test() { + "support put" in { + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until initsz) assert(ct.put(new Wrap(i), i) == None) + for (i <- 0 until initsz) assert(ct.put(new Wrap(i), -i) == Some(i)) + } + + "support put if absent" in { + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until initsz) ct.update(new Wrap(i), i) + for (i <- 0 until initsz) assert(ct.putIfAbsent(new Wrap(i), -i) == Some(i)) + for (i <- 0 until initsz) assert(ct.putIfAbsent(new Wrap(i), -i) == Some(i)) + for (i <- initsz until secondsz) assert(ct.putIfAbsent(new Wrap(i), -i) == None) + for (i <- initsz until secondsz) assert(ct.putIfAbsent(new Wrap(i), i) == Some(-i)) + } + + "support remove if mapped to a specific value" in { + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until initsz) ct.update(new Wrap(i), i) + for (i <- 0 until initsz) assert(ct.remove(new Wrap(i), -i - 1) == false) + for (i <- 0 until initsz) assert(ct.remove(new Wrap(i), i) == true) + for (i <- 0 until initsz) assert(ct.remove(new Wrap(i), i) == false) + } + + "support replace if mapped to a specific value" in { + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until initsz) ct.update(new Wrap(i), i) + for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), -i - 1, -i - 2) == false) + for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), i, -i - 2) == true) + for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), i, -i - 2) == false) + for (i <- initsz until secondsz) assert(ct.replace(new Wrap(i), i, 0) == false) + } + + "support replace if present" in { + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until initsz) ct.update(new Wrap(i), i) + for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), -i) == Some(i)) + for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), i) == Some(-i)) + for (i <- initsz until secondsz) assert(ct.replace(new Wrap(i), i) == None) + } + + def assertEqual(a: Any, b: Any) = { + if (a != b) println(a, b) + assert(a == b) + } + + "support replace if mapped to a specific value, using several threads" in { + val ct = new TrieMap[Wrap, Int] + val sz = 55000 + for (i <- 0 until sz) ct.update(new Wrap(i), i) + + class Updater(index: Int, offs: Int) extends Thread { + override def run() { + var repeats = 0 + for (i <- 0 until sz) { + val j = (offs + i) % sz + var k = Int.MaxValue + do { + if (k != Int.MaxValue) repeats += 1 + k = ct.lookup(new Wrap(j)) + } while (!ct.replace(new Wrap(j), k, -k)) + } + //println("Thread %d repeats: %d".format(index, repeats)) + } + } + + val threads = for (i <- 0 until 16) yield new Updater(i, sz / 32 * i) + threads.foreach(_.start()) + threads.foreach(_.join()) + + for (i <- 0 until sz) assertEqual(ct(new Wrap(i)), i) + + val threads2 = for (i <- 0 until 15) yield new Updater(i, sz / 32 * i) + threads2.foreach(_.start()) + threads2.foreach(_.join()) + + for (i <- 0 until sz) assertEqual(ct(new Wrap(i)), -i) + } + + "support put if absent, several threads" in { + val ct = new TrieMap[Wrap, Int] + val sz = 110000 + + class Updater(offs: Int) extends Thread { + override def run() { + for (i <- 0 until sz) { + val j = (offs + i) % sz + ct.putIfAbsent(new Wrap(j), j) + assert(ct.lookup(new Wrap(j)) == j) + } + } + } + + val threads = for (i <- 0 until 16) yield new Updater(sz / 32 * i) + threads.foreach(_.start()) + threads.foreach(_.join()) + + for (i <- 0 until sz) assert(ct(new Wrap(i)) == i) + } + + "support remove if mapped to a specific value, several threads" in { + val ct = new TrieMap[Wrap, Int] + val sz = 55000 + for (i <- 0 until sz) ct.update(new Wrap(i), i) + + class Remover(offs: Int) extends Thread { + override def run() { + for (i <- 0 until sz) { + val j = (offs + i) % sz + ct.remove(new Wrap(j), j) + assert(ct.get(new Wrap(j)) == None) + } + } + } + + val threads = for (i <- 0 until 16) yield new Remover(sz / 32 * i) + threads.foreach(_.start()) + threads.foreach(_.join()) + + for (i <- 0 until sz) assert(ct.get(new Wrap(i)) == None) + } + + "have all or none of the elements depending on the oddity" in { + val ct = new TrieMap[Wrap, Int] + val sz = 65000 + for (i <- 0 until sz) ct(new Wrap(i)) = i + + class Modifier(index: Int, offs: Int) extends Thread { + override def run() { + for (j <- 0 until sz) { + val i = (offs + j) % sz + var success = false + do { + if (ct.contains(new Wrap(i))) { + success = ct.remove(new Wrap(i)) != None + } else { + success = ct.putIfAbsent(new Wrap(i), i) == None + } + } while (!success) + } + } + } + + def modify(n: Int) = { + val threads = for (i <- 0 until n) yield new Modifier(i, sz / n * i) + threads.foreach(_.start()) + threads.foreach(_.join()) + } + + modify(16) + for (i <- 0 until sz) assertEqual(ct.get(new Wrap(i)), Some(i)) + modify(15) + for (i <- 0 until sz) assertEqual(ct.get(new Wrap(i)), None) + } + + "compute size correctly" in { + val ct = new TrieMap[Wrap, Int] + val sz = 36450 + for (i <- 0 until sz) ct(new Wrap(i)) = i + + assertEqual(ct.size, sz) + assertEqual(ct.size, sz) + } + + "compute size correctly in parallel" in { + val ct = new TrieMap[Wrap, Int] + val sz = 36450 + for (i <- 0 until sz) ct(new Wrap(i)) = i + val pct = ct.par + + assertEqual(pct.size, sz) + assertEqual(pct.size, sz) + } + + } + +} diff --git a/test/files/run/ctries-new/iterator.scala b/test/files/run/ctries-new/iterator.scala new file mode 100644 index 0000000000..b953a40e00 --- /dev/null +++ b/test/files/run/ctries-new/iterator.scala @@ -0,0 +1,289 @@ + + + + +import collection._ +import collection.concurrent.TrieMap + + + +object IteratorSpec extends Spec { + + def test() { + "work for an empty trie" in { + val ct = new TrieMap + val it = ct.iterator + + it.hasNext shouldEqual (false) + evaluating { it.next() }.shouldProduce [NoSuchElementException] + } + + def nonEmptyIteratorCheck(sz: Int) { + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct.put(new Wrap(i), i) + + val it = ct.iterator + val tracker = mutable.Map[Wrap, Int]() + for (i <- 0 until sz) { + assert(it.hasNext == true) + tracker += it.next + } + + it.hasNext shouldEqual (false) + evaluating { it.next() }.shouldProduce [NoSuchElementException] + tracker.size shouldEqual (sz) + tracker shouldEqual (ct) + } + + "work for a 1 element trie" in { + nonEmptyIteratorCheck(1) + } + + "work for a 2 element trie" in { + nonEmptyIteratorCheck(2) + } + + "work for a 3 element trie" in { + nonEmptyIteratorCheck(3) + } + + "work for a 5 element trie" in { + nonEmptyIteratorCheck(5) + } + + "work for a 10 element trie" in { + nonEmptyIteratorCheck(10) + } + + "work for a 20 element trie" in { + nonEmptyIteratorCheck(20) + } + + "work for a 50 element trie" in { + nonEmptyIteratorCheck(50) + } + + "work for a 100 element trie" in { + nonEmptyIteratorCheck(100) + } + + "work for a 1k element trie" in { + nonEmptyIteratorCheck(1000) + } + + "work for a 5k element trie" in { + nonEmptyIteratorCheck(5000) + } + + "work for a 75k element trie" in { + nonEmptyIteratorCheck(75000) + } + + "work for a 250k element trie" in { + nonEmptyIteratorCheck(500000) + } + + def nonEmptyCollideCheck(sz: Int) { + val ct = new TrieMap[DumbHash, Int] + for (i <- 0 until sz) ct.put(new DumbHash(i), i) + + val it = ct.iterator + val tracker = mutable.Map[DumbHash, Int]() + for (i <- 0 until sz) { + assert(it.hasNext == true) + tracker += it.next + } + + it.hasNext shouldEqual (false) + evaluating { it.next() }.shouldProduce [NoSuchElementException] + tracker.size shouldEqual (sz) + tracker shouldEqual (ct) + } + + "work for colliding hashcodes, 2 element trie" in { + nonEmptyCollideCheck(2) + } + + "work for colliding hashcodes, 3 element trie" in { + nonEmptyCollideCheck(3) + } + + "work for colliding hashcodes, 5 element trie" in { + nonEmptyCollideCheck(5) + } + + "work for colliding hashcodes, 10 element trie" in { + nonEmptyCollideCheck(10) + } + + "work for colliding hashcodes, 100 element trie" in { + nonEmptyCollideCheck(100) + } + + "work for colliding hashcodes, 500 element trie" in { + nonEmptyCollideCheck(500) + } + + "work for colliding hashcodes, 5k element trie" in { + nonEmptyCollideCheck(5000) + } + + def assertEqual(a: Map[Wrap, Int], b: Map[Wrap, Int]) { + if (a != b) { + println(a.size + " vs " + b.size) + // println(a) + // println(b) + // println(a.toSeq.sortBy((x: (Wrap, Int)) => x._1.i)) + // println(b.toSeq.sortBy((x: (Wrap, Int)) => x._1.i)) + } + assert(a == b) + } + + "be consistent when taken with concurrent modifications" in { + val sz = 25000 + val W = 15 + val S = 5 + val checks = 5 + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct.put(new Wrap(i), i) + + class Modifier extends Thread { + override def run() { + for (i <- 0 until sz) ct.putIfAbsent(new Wrap(i), i) match { + case Some(_) => ct.remove(new Wrap(i)) + case None => + } + } + } + + def consistentIteration(ct: TrieMap[Wrap, Int], checks: Int) { + class Iter extends Thread { + override def run() { + val snap = ct.readOnlySnapshot() + val initial = mutable.Map[Wrap, Int]() + for (kv <- snap) initial += kv + + for (i <- 0 until checks) { + assertEqual(snap.iterator.toMap, initial) + } + } + } + + val iter = new Iter + iter.start() + iter.join() + } + + val threads = for (_ <- 0 until W) yield new Modifier + threads.foreach(_.start()) + for (_ <- 0 until S) consistentIteration(ct, checks) + threads.foreach(_.join()) + } + + "be consistent with a concurrent removal with a well defined order" in { + val sz = 150000 + val sgroupsize = 10 + val sgroupnum = 5 + val removerslowdown = 50 + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct.put(new Wrap(i), i) + + class Remover extends Thread { + override def run() { + for (i <- 0 until sz) { + assert(ct.remove(new Wrap(i)) == Some(i)) + for (i <- 0 until removerslowdown) ct.get(new Wrap(i)) // slow down, mate + } + //println("done removing") + } + } + + def consistentIteration(it: Iterator[(Wrap, Int)]) = { + class Iter extends Thread { + override def run() { + val elems = it.toBuffer + if (elems.nonEmpty) { + val minelem = elems.minBy((x: (Wrap, Int)) => x._1.i)._1.i + assert(elems.forall(_._1.i >= minelem)) + } + } + } + new Iter + } + + val remover = new Remover + remover.start() + for (_ <- 0 until sgroupnum) { + val iters = for (_ <- 0 until sgroupsize) yield consistentIteration(ct.iterator) + iters.foreach(_.start()) + iters.foreach(_.join()) + } + //println("done with iterators") + remover.join() + } + + "be consistent with a concurrent insertion with a well defined order" in { + val sz = 150000 + val sgroupsize = 10 + val sgroupnum = 10 + val inserterslowdown = 50 + val ct = new TrieMap[Wrap, Int] + + class Inserter extends Thread { + override def run() { + for (i <- 0 until sz) { + assert(ct.put(new Wrap(i), i) == None) + for (i <- 0 until inserterslowdown) ct.get(new Wrap(i)) // slow down, mate + } + //println("done inserting") + } + } + + def consistentIteration(it: Iterator[(Wrap, Int)]) = { + class Iter extends Thread { + override def run() { + val elems = it.toSeq + if (elems.nonEmpty) { + val maxelem = elems.maxBy((x: (Wrap, Int)) => x._1.i)._1.i + assert(elems.forall(_._1.i <= maxelem)) + } + } + } + new Iter + } + + val inserter = new Inserter + inserter.start() + for (_ <- 0 until sgroupnum) { + val iters = for (_ <- 0 until sgroupsize) yield consistentIteration(ct.iterator) + iters.foreach(_.start()) + iters.foreach(_.join()) + } + //println("done with iterators") + inserter.join() + } + + "work on a yet unevaluated snapshot" in { + val sz = 50000 + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct.update(new Wrap(i), i) + + val snap = ct.snapshot() + val it = snap.iterator + + while (it.hasNext) it.next() + } + + "be duplicated" in { + val sz = 50 + val ct = collection.parallel.mutable.ParTrieMap((0 until sz) zip (0 until sz): _*) + val it = ct.splitter + for (_ <- 0 until (sz / 2)) it.next() + val dupit = it.dup + + it.toList shouldEqual dupit.toList + } + + } + +} diff --git a/test/files/run/ctries-new/lnode.scala b/test/files/run/ctries-new/lnode.scala new file mode 100644 index 0000000000..92a31088e5 --- /dev/null +++ b/test/files/run/ctries-new/lnode.scala @@ -0,0 +1,61 @@ + + + +import collection.concurrent.TrieMap + + +object LNodeSpec extends Spec { + + val initsz = 1500 + val secondsz = 1750 + + def test() { + "accept elements with the same hash codes" in { + val ct = new TrieMap[DumbHash, Int] + for (i <- 0 until initsz) ct.update(new DumbHash(i), i) + } + + "lookup elements with the same hash codes" in { + val ct = new TrieMap[DumbHash, Int] + for (i <- 0 until initsz) ct.update(new DumbHash(i), i) + for (i <- 0 until initsz) assert(ct.get(new DumbHash(i)) == Some(i)) + for (i <- initsz until secondsz) assert(ct.get(new DumbHash(i)) == None) + } + + "remove elements with the same hash codes" in { + val ct = new TrieMap[DumbHash, Int] + for (i <- 0 until initsz) ct.update(new DumbHash(i), i) + for (i <- 0 until initsz) { + val remelem = ct.remove(new DumbHash(i)) + assert(remelem == Some(i), "removing " + i + " yields " + remelem) + } + for (i <- 0 until initsz) assert(ct.get(new DumbHash(i)) == None) + } + + "put elements with the same hash codes if absent" in { + val ct = new TrieMap[DumbHash, Int] + for (i <- 0 until initsz) ct.put(new DumbHash(i), i) + for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == i) + for (i <- 0 until initsz) assert(ct.putIfAbsent(new DumbHash(i), i) == Some(i)) + for (i <- initsz until secondsz) assert(ct.putIfAbsent(new DumbHash(i), i) == None) + for (i <- initsz until secondsz) assert(ct.lookup(new DumbHash(i)) == i) + } + + "replace elements with the same hash codes" in { + val ct = new TrieMap[DumbHash, Int] + for (i <- 0 until initsz) assert(ct.put(new DumbHash(i), i) == None) + for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == i) + for (i <- 0 until initsz) assert(ct.replace(new DumbHash(i), -i) == Some(i)) + for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == -i) + for (i <- 0 until initsz) assert(ct.replace(new DumbHash(i), -i, i) == true) + } + + "remove elements with the same hash codes if mapped to a specific value" in { + val ct = new TrieMap[DumbHash, Int] + for (i <- 0 until initsz) assert(ct.put(new DumbHash(i), i) == None) + for (i <- 0 until initsz) assert(ct.remove(new DumbHash(i), i) == true) + } + + } + +} diff --git a/test/files/run/ctries-new/main.scala b/test/files/run/ctries-new/main.scala new file mode 100644 index 0000000000..1d40dab6c5 --- /dev/null +++ b/test/files/run/ctries-new/main.scala @@ -0,0 +1,45 @@ + + + + + + + +object Test { + + def main(args: Array[String]) { + ConcurrentMapSpec.test() + IteratorSpec.test() + LNodeSpec.test() + SnapshotSpec.test() + } + +} + + +trait Spec { + + implicit def str2ops(s: String) = new { + def in[U](body: =>U) { + // just execute body + body + } + } + + implicit def any2ops(a: Any) = new { + def shouldEqual(other: Any) = assert(a == other) + } + + def evaluating[U](body: =>U) = new { + def shouldProduce[T <: Throwable: ClassTag]() = { + var produced = false + try body + catch { + case e => if (e.getClass == implicitly[ClassTag[T]].erasure) produced = true + } finally { + assert(produced, "Did not produce exception of type: " + implicitly[ClassTag[T]]) + } + } + } + +} diff --git a/test/files/run/ctries-new/snapshot.scala b/test/files/run/ctries-new/snapshot.scala new file mode 100644 index 0000000000..5fe77d445b --- /dev/null +++ b/test/files/run/ctries-new/snapshot.scala @@ -0,0 +1,267 @@ + + + + +import collection._ +import collection.concurrent.TrieMap + + + +object SnapshotSpec extends Spec { + + def test() { + "support snapshots" in { + val ctn = new TrieMap + ctn.snapshot() + ctn.readOnlySnapshot() + + val ct = new TrieMap[Int, Int] + for (i <- 0 until 100) ct.put(i, i) + ct.snapshot() + ct.readOnlySnapshot() + } + + "empty 2 quiescent snapshots in isolation" in { + val sz = 4000 + + class Worker(trie: TrieMap[Wrap, Int]) extends Thread { + override def run() { + for (i <- 0 until sz) { + assert(trie.remove(new Wrap(i)) == Some(i)) + for (j <- 0 until sz) + if (j <= i) assert(trie.get(new Wrap(j)) == None) + else assert(trie.get(new Wrap(j)) == Some(j)) + } + } + } + + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct.put(new Wrap(i), i) + val snapt = ct.snapshot() + + val original = new Worker(ct) + val snapshot = new Worker(snapt) + original.start() + snapshot.start() + original.join() + snapshot.join() + + for (i <- 0 until sz) { + assert(ct.get(new Wrap(i)) == None) + assert(snapt.get(new Wrap(i)) == None) + } + } + + def consistentReadOnly(name: String, readonly: Map[Wrap, Int], sz: Int, N: Int) { + @volatile var e: Exception = null + + // reads possible entries once and stores them + // then reads all these N more times to check if the + // state stayed the same + class Reader(trie: Map[Wrap, Int]) extends Thread { + setName("Reader " + name) + + override def run() = + try check() + catch { + case ex: Exception => e = ex + } + + def check() { + val initial = mutable.Map[Wrap, Int]() + for (i <- 0 until sz) trie.get(new Wrap(i)) match { + case Some(i) => initial.put(new Wrap(i), i) + case None => // do nothing + } + + for (k <- 0 until N) { + for (i <- 0 until sz) { + val tres = trie.get(new Wrap(i)) + val ires = initial.get(new Wrap(i)) + if (tres != ires) println(i, "initially: " + ires, "traversal %d: %s".format(k, tres)) + assert(tres == ires) + } + } + } + } + + val reader = new Reader(readonly) + reader.start() + reader.join() + + if (e ne null) { + e.printStackTrace() + throw e + } + } + + // traverses the trie `rep` times and modifies each entry + class Modifier(trie: TrieMap[Wrap, Int], index: Int, rep: Int, sz: Int) extends Thread { + setName("Modifier %d".format(index)) + + override def run() { + for (k <- 0 until rep) { + for (i <- 0 until sz) trie.putIfAbsent(new Wrap(i), i) match { + case Some(_) => trie.remove(new Wrap(i)) + case None => // do nothing + } + } + } + } + + // removes all the elements from the trie + class Remover(trie: TrieMap[Wrap, Int], index: Int, totremovers: Int, sz: Int) extends Thread { + setName("Remover %d".format(index)) + + override def run() { + for (i <- 0 until sz) trie.remove(new Wrap((i + sz / totremovers * index) % sz)) + } + } + + "have a consistent quiescent read-only snapshot" in { + val sz = 10000 + val N = 100 + val W = 10 + + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct(new Wrap(i)) = i + val readonly = ct.readOnlySnapshot() + val threads = for (i <- 0 until W) yield new Modifier(ct, i, N, sz) + + threads.foreach(_.start()) + consistentReadOnly("qm", readonly, sz, N) + threads.foreach(_.join()) + } + + // now, we check non-quiescent snapshots, as these permit situations + // where a thread is caught in the middle of the update when a snapshot is taken + + "have a consistent non-quiescent read-only snapshot, concurrent with removes only" in { + val sz = 1250 + val W = 100 + val S = 5000 + + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct(new Wrap(i)) = i + val threads = for (i <- 0 until W) yield new Remover(ct, i, W, sz) + + threads.foreach(_.start()) + for (i <- 0 until S) consistentReadOnly("non-qr", ct.readOnlySnapshot(), sz, 5) + threads.foreach(_.join()) + } + + "have a consistent non-quiescent read-only snapshot, concurrent with modifications" in { + val sz = 1000 + val N = 7000 + val W = 10 + val S = 7000 + + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct(new Wrap(i)) = i + val threads = for (i <- 0 until W) yield new Modifier(ct, i, N, sz) + + threads.foreach(_.start()) + for (i <- 0 until S) consistentReadOnly("non-qm", ct.readOnlySnapshot(), sz, 5) + threads.foreach(_.join()) + } + + def consistentNonReadOnly(name: String, trie: TrieMap[Wrap, Int], sz: Int, N: Int) { + @volatile var e: Exception = null + + // reads possible entries once and stores them + // then reads all these N more times to check if the + // state stayed the same + class Worker extends Thread { + setName("Worker " + name) + + override def run() = + try check() + catch { + case ex: Exception => e = ex + } + + def check() { + val initial = mutable.Map[Wrap, Int]() + for (i <- 0 until sz) trie.get(new Wrap(i)) match { + case Some(i) => initial.put(new Wrap(i), i) + case None => // do nothing + } + + for (k <- 0 until N) { + // modify + for ((key, value) <- initial) { + val oldv = if (k % 2 == 0) value else -value + val newv = -oldv + trie.replace(key, oldv, newv) + } + + // check + for (i <- 0 until sz) if (initial.contains(new Wrap(i))) { + val expected = if (k % 2 == 0) -i else i + //println(trie.get(new Wrap(i))) + assert(trie.get(new Wrap(i)) == Some(expected)) + } else { + assert(trie.get(new Wrap(i)) == None) + } + } + } + } + + val worker = new Worker + worker.start() + worker.join() + + if (e ne null) { + e.printStackTrace() + throw e + } + } + + "have a consistent non-quiescent snapshot, concurrent with modifications" in { + val sz = 9000 + val N = 1000 + val W = 10 + val S = 400 + + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct(new Wrap(i)) = i + val threads = for (i <- 0 until W) yield new Modifier(ct, i, N, sz) + + threads.foreach(_.start()) + for (i <- 0 until S) { + consistentReadOnly("non-qm", ct.snapshot(), sz, 5) + consistentNonReadOnly("non-qsnap", ct.snapshot(), sz, 5) + } + threads.foreach(_.join()) + } + + "work when many concurrent snapshots are taken, concurrent with modifications" in { + val sz = 12000 + val W = 10 + val S = 10 + val modifytimes = 1200 + val snaptimes = 600 + val ct = new TrieMap[Wrap, Int] + for (i <- 0 until sz) ct(new Wrap(i)) = i + + class Snapshooter extends Thread { + setName("Snapshooter") + override def run() { + for (k <- 0 until snaptimes) { + val snap = ct.snapshot() + for (i <- 0 until sz) snap.remove(new Wrap(i)) + for (i <- 0 until sz) assert(!snap.contains(new Wrap(i))) + } + } + } + + val mods = for (i <- 0 until W) yield new Modifier(ct, i, modifytimes, sz) + val shooters = for (i <- 0 until S) yield new Snapshooter + val threads = mods ++ shooters + threads.foreach(_.start()) + threads.foreach(_.join()) + } + + } + +} diff --git a/test/files/run/ctries/DumbHash.scala b/test/files/run/ctries/DumbHash.scala deleted file mode 100644 index 8ef325b67c..0000000000 --- a/test/files/run/ctries/DumbHash.scala +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - -class DumbHash(val i: Int) { - override def equals(other: Any) = other match { - case that: DumbHash => that.i == this.i - case _ => false - } - override def hashCode = i % 5 - override def toString = "DH(%s)".format(i) -} diff --git a/test/files/run/ctries/Wrap.scala b/test/files/run/ctries/Wrap.scala deleted file mode 100644 index 7b645c1612..0000000000 --- a/test/files/run/ctries/Wrap.scala +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - -case class Wrap(i: Int) { - override def hashCode = i * 0x9e3775cd -} diff --git a/test/files/run/ctries/concmap.scala b/test/files/run/ctries/concmap.scala deleted file mode 100644 index 3ec0256afb..0000000000 --- a/test/files/run/ctries/concmap.scala +++ /dev/null @@ -1,188 +0,0 @@ - - - -import collection.concurrent.TrieMap - - -object ConcurrentMapSpec extends Spec { - - val initsz = 500 - val secondsz = 750 - - def test() { - "support put" in { - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until initsz) assert(ct.put(new Wrap(i), i) == None) - for (i <- 0 until initsz) assert(ct.put(new Wrap(i), -i) == Some(i)) - } - - "support put if absent" in { - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until initsz) ct.update(new Wrap(i), i) - for (i <- 0 until initsz) assert(ct.putIfAbsent(new Wrap(i), -i) == Some(i)) - for (i <- 0 until initsz) assert(ct.putIfAbsent(new Wrap(i), -i) == Some(i)) - for (i <- initsz until secondsz) assert(ct.putIfAbsent(new Wrap(i), -i) == None) - for (i <- initsz until secondsz) assert(ct.putIfAbsent(new Wrap(i), i) == Some(-i)) - } - - "support remove if mapped to a specific value" in { - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until initsz) ct.update(new Wrap(i), i) - for (i <- 0 until initsz) assert(ct.remove(new Wrap(i), -i - 1) == false) - for (i <- 0 until initsz) assert(ct.remove(new Wrap(i), i) == true) - for (i <- 0 until initsz) assert(ct.remove(new Wrap(i), i) == false) - } - - "support replace if mapped to a specific value" in { - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until initsz) ct.update(new Wrap(i), i) - for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), -i - 1, -i - 2) == false) - for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), i, -i - 2) == true) - for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), i, -i - 2) == false) - for (i <- initsz until secondsz) assert(ct.replace(new Wrap(i), i, 0) == false) - } - - "support replace if present" in { - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until initsz) ct.update(new Wrap(i), i) - for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), -i) == Some(i)) - for (i <- 0 until initsz) assert(ct.replace(new Wrap(i), i) == Some(-i)) - for (i <- initsz until secondsz) assert(ct.replace(new Wrap(i), i) == None) - } - - def assertEqual(a: Any, b: Any) = { - if (a != b) println(a, b) - assert(a == b) - } - - "support replace if mapped to a specific value, using several threads" in { - val ct = new TrieMap[Wrap, Int] - val sz = 55000 - for (i <- 0 until sz) ct.update(new Wrap(i), i) - - class Updater(index: Int, offs: Int) extends Thread { - override def run() { - var repeats = 0 - for (i <- 0 until sz) { - val j = (offs + i) % sz - var k = Int.MaxValue - do { - if (k != Int.MaxValue) repeats += 1 - k = ct.lookup(new Wrap(j)) - } while (!ct.replace(new Wrap(j), k, -k)) - } - //println("Thread %d repeats: %d".format(index, repeats)) - } - } - - val threads = for (i <- 0 until 16) yield new Updater(i, sz / 32 * i) - threads.foreach(_.start()) - threads.foreach(_.join()) - - for (i <- 0 until sz) assertEqual(ct(new Wrap(i)), i) - - val threads2 = for (i <- 0 until 15) yield new Updater(i, sz / 32 * i) - threads2.foreach(_.start()) - threads2.foreach(_.join()) - - for (i <- 0 until sz) assertEqual(ct(new Wrap(i)), -i) - } - - "support put if absent, several threads" in { - val ct = new TrieMap[Wrap, Int] - val sz = 110000 - - class Updater(offs: Int) extends Thread { - override def run() { - for (i <- 0 until sz) { - val j = (offs + i) % sz - ct.putIfAbsent(new Wrap(j), j) - assert(ct.lookup(new Wrap(j)) == j) - } - } - } - - val threads = for (i <- 0 until 16) yield new Updater(sz / 32 * i) - threads.foreach(_.start()) - threads.foreach(_.join()) - - for (i <- 0 until sz) assert(ct(new Wrap(i)) == i) - } - - "support remove if mapped to a specific value, several threads" in { - val ct = new TrieMap[Wrap, Int] - val sz = 55000 - for (i <- 0 until sz) ct.update(new Wrap(i), i) - - class Remover(offs: Int) extends Thread { - override def run() { - for (i <- 0 until sz) { - val j = (offs + i) % sz - ct.remove(new Wrap(j), j) - assert(ct.get(new Wrap(j)) == None) - } - } - } - - val threads = for (i <- 0 until 16) yield new Remover(sz / 32 * i) - threads.foreach(_.start()) - threads.foreach(_.join()) - - for (i <- 0 until sz) assert(ct.get(new Wrap(i)) == None) - } - - "have all or none of the elements depending on the oddity" in { - val ct = new TrieMap[Wrap, Int] - val sz = 65000 - for (i <- 0 until sz) ct(new Wrap(i)) = i - - class Modifier(index: Int, offs: Int) extends Thread { - override def run() { - for (j <- 0 until sz) { - val i = (offs + j) % sz - var success = false - do { - if (ct.contains(new Wrap(i))) { - success = ct.remove(new Wrap(i)) != None - } else { - success = ct.putIfAbsent(new Wrap(i), i) == None - } - } while (!success) - } - } - } - - def modify(n: Int) = { - val threads = for (i <- 0 until n) yield new Modifier(i, sz / n * i) - threads.foreach(_.start()) - threads.foreach(_.join()) - } - - modify(16) - for (i <- 0 until sz) assertEqual(ct.get(new Wrap(i)), Some(i)) - modify(15) - for (i <- 0 until sz) assertEqual(ct.get(new Wrap(i)), None) - } - - "compute size correctly" in { - val ct = new TrieMap[Wrap, Int] - val sz = 36450 - for (i <- 0 until sz) ct(new Wrap(i)) = i - - assertEqual(ct.size, sz) - assertEqual(ct.size, sz) - } - - "compute size correctly in parallel" in { - val ct = new TrieMap[Wrap, Int] - val sz = 36450 - for (i <- 0 until sz) ct(new Wrap(i)) = i - val pct = ct.par - - assertEqual(pct.size, sz) - assertEqual(pct.size, sz) - } - - } - -} diff --git a/test/files/run/ctries/iterator.scala b/test/files/run/ctries/iterator.scala deleted file mode 100644 index b953a40e00..0000000000 --- a/test/files/run/ctries/iterator.scala +++ /dev/null @@ -1,289 +0,0 @@ - - - - -import collection._ -import collection.concurrent.TrieMap - - - -object IteratorSpec extends Spec { - - def test() { - "work for an empty trie" in { - val ct = new TrieMap - val it = ct.iterator - - it.hasNext shouldEqual (false) - evaluating { it.next() }.shouldProduce [NoSuchElementException] - } - - def nonEmptyIteratorCheck(sz: Int) { - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct.put(new Wrap(i), i) - - val it = ct.iterator - val tracker = mutable.Map[Wrap, Int]() - for (i <- 0 until sz) { - assert(it.hasNext == true) - tracker += it.next - } - - it.hasNext shouldEqual (false) - evaluating { it.next() }.shouldProduce [NoSuchElementException] - tracker.size shouldEqual (sz) - tracker shouldEqual (ct) - } - - "work for a 1 element trie" in { - nonEmptyIteratorCheck(1) - } - - "work for a 2 element trie" in { - nonEmptyIteratorCheck(2) - } - - "work for a 3 element trie" in { - nonEmptyIteratorCheck(3) - } - - "work for a 5 element trie" in { - nonEmptyIteratorCheck(5) - } - - "work for a 10 element trie" in { - nonEmptyIteratorCheck(10) - } - - "work for a 20 element trie" in { - nonEmptyIteratorCheck(20) - } - - "work for a 50 element trie" in { - nonEmptyIteratorCheck(50) - } - - "work for a 100 element trie" in { - nonEmptyIteratorCheck(100) - } - - "work for a 1k element trie" in { - nonEmptyIteratorCheck(1000) - } - - "work for a 5k element trie" in { - nonEmptyIteratorCheck(5000) - } - - "work for a 75k element trie" in { - nonEmptyIteratorCheck(75000) - } - - "work for a 250k element trie" in { - nonEmptyIteratorCheck(500000) - } - - def nonEmptyCollideCheck(sz: Int) { - val ct = new TrieMap[DumbHash, Int] - for (i <- 0 until sz) ct.put(new DumbHash(i), i) - - val it = ct.iterator - val tracker = mutable.Map[DumbHash, Int]() - for (i <- 0 until sz) { - assert(it.hasNext == true) - tracker += it.next - } - - it.hasNext shouldEqual (false) - evaluating { it.next() }.shouldProduce [NoSuchElementException] - tracker.size shouldEqual (sz) - tracker shouldEqual (ct) - } - - "work for colliding hashcodes, 2 element trie" in { - nonEmptyCollideCheck(2) - } - - "work for colliding hashcodes, 3 element trie" in { - nonEmptyCollideCheck(3) - } - - "work for colliding hashcodes, 5 element trie" in { - nonEmptyCollideCheck(5) - } - - "work for colliding hashcodes, 10 element trie" in { - nonEmptyCollideCheck(10) - } - - "work for colliding hashcodes, 100 element trie" in { - nonEmptyCollideCheck(100) - } - - "work for colliding hashcodes, 500 element trie" in { - nonEmptyCollideCheck(500) - } - - "work for colliding hashcodes, 5k element trie" in { - nonEmptyCollideCheck(5000) - } - - def assertEqual(a: Map[Wrap, Int], b: Map[Wrap, Int]) { - if (a != b) { - println(a.size + " vs " + b.size) - // println(a) - // println(b) - // println(a.toSeq.sortBy((x: (Wrap, Int)) => x._1.i)) - // println(b.toSeq.sortBy((x: (Wrap, Int)) => x._1.i)) - } - assert(a == b) - } - - "be consistent when taken with concurrent modifications" in { - val sz = 25000 - val W = 15 - val S = 5 - val checks = 5 - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct.put(new Wrap(i), i) - - class Modifier extends Thread { - override def run() { - for (i <- 0 until sz) ct.putIfAbsent(new Wrap(i), i) match { - case Some(_) => ct.remove(new Wrap(i)) - case None => - } - } - } - - def consistentIteration(ct: TrieMap[Wrap, Int], checks: Int) { - class Iter extends Thread { - override def run() { - val snap = ct.readOnlySnapshot() - val initial = mutable.Map[Wrap, Int]() - for (kv <- snap) initial += kv - - for (i <- 0 until checks) { - assertEqual(snap.iterator.toMap, initial) - } - } - } - - val iter = new Iter - iter.start() - iter.join() - } - - val threads = for (_ <- 0 until W) yield new Modifier - threads.foreach(_.start()) - for (_ <- 0 until S) consistentIteration(ct, checks) - threads.foreach(_.join()) - } - - "be consistent with a concurrent removal with a well defined order" in { - val sz = 150000 - val sgroupsize = 10 - val sgroupnum = 5 - val removerslowdown = 50 - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct.put(new Wrap(i), i) - - class Remover extends Thread { - override def run() { - for (i <- 0 until sz) { - assert(ct.remove(new Wrap(i)) == Some(i)) - for (i <- 0 until removerslowdown) ct.get(new Wrap(i)) // slow down, mate - } - //println("done removing") - } - } - - def consistentIteration(it: Iterator[(Wrap, Int)]) = { - class Iter extends Thread { - override def run() { - val elems = it.toBuffer - if (elems.nonEmpty) { - val minelem = elems.minBy((x: (Wrap, Int)) => x._1.i)._1.i - assert(elems.forall(_._1.i >= minelem)) - } - } - } - new Iter - } - - val remover = new Remover - remover.start() - for (_ <- 0 until sgroupnum) { - val iters = for (_ <- 0 until sgroupsize) yield consistentIteration(ct.iterator) - iters.foreach(_.start()) - iters.foreach(_.join()) - } - //println("done with iterators") - remover.join() - } - - "be consistent with a concurrent insertion with a well defined order" in { - val sz = 150000 - val sgroupsize = 10 - val sgroupnum = 10 - val inserterslowdown = 50 - val ct = new TrieMap[Wrap, Int] - - class Inserter extends Thread { - override def run() { - for (i <- 0 until sz) { - assert(ct.put(new Wrap(i), i) == None) - for (i <- 0 until inserterslowdown) ct.get(new Wrap(i)) // slow down, mate - } - //println("done inserting") - } - } - - def consistentIteration(it: Iterator[(Wrap, Int)]) = { - class Iter extends Thread { - override def run() { - val elems = it.toSeq - if (elems.nonEmpty) { - val maxelem = elems.maxBy((x: (Wrap, Int)) => x._1.i)._1.i - assert(elems.forall(_._1.i <= maxelem)) - } - } - } - new Iter - } - - val inserter = new Inserter - inserter.start() - for (_ <- 0 until sgroupnum) { - val iters = for (_ <- 0 until sgroupsize) yield consistentIteration(ct.iterator) - iters.foreach(_.start()) - iters.foreach(_.join()) - } - //println("done with iterators") - inserter.join() - } - - "work on a yet unevaluated snapshot" in { - val sz = 50000 - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct.update(new Wrap(i), i) - - val snap = ct.snapshot() - val it = snap.iterator - - while (it.hasNext) it.next() - } - - "be duplicated" in { - val sz = 50 - val ct = collection.parallel.mutable.ParTrieMap((0 until sz) zip (0 until sz): _*) - val it = ct.splitter - for (_ <- 0 until (sz / 2)) it.next() - val dupit = it.dup - - it.toList shouldEqual dupit.toList - } - - } - -} diff --git a/test/files/run/ctries/lnode.scala b/test/files/run/ctries/lnode.scala deleted file mode 100644 index 92a31088e5..0000000000 --- a/test/files/run/ctries/lnode.scala +++ /dev/null @@ -1,61 +0,0 @@ - - - -import collection.concurrent.TrieMap - - -object LNodeSpec extends Spec { - - val initsz = 1500 - val secondsz = 1750 - - def test() { - "accept elements with the same hash codes" in { - val ct = new TrieMap[DumbHash, Int] - for (i <- 0 until initsz) ct.update(new DumbHash(i), i) - } - - "lookup elements with the same hash codes" in { - val ct = new TrieMap[DumbHash, Int] - for (i <- 0 until initsz) ct.update(new DumbHash(i), i) - for (i <- 0 until initsz) assert(ct.get(new DumbHash(i)) == Some(i)) - for (i <- initsz until secondsz) assert(ct.get(new DumbHash(i)) == None) - } - - "remove elements with the same hash codes" in { - val ct = new TrieMap[DumbHash, Int] - for (i <- 0 until initsz) ct.update(new DumbHash(i), i) - for (i <- 0 until initsz) { - val remelem = ct.remove(new DumbHash(i)) - assert(remelem == Some(i), "removing " + i + " yields " + remelem) - } - for (i <- 0 until initsz) assert(ct.get(new DumbHash(i)) == None) - } - - "put elements with the same hash codes if absent" in { - val ct = new TrieMap[DumbHash, Int] - for (i <- 0 until initsz) ct.put(new DumbHash(i), i) - for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == i) - for (i <- 0 until initsz) assert(ct.putIfAbsent(new DumbHash(i), i) == Some(i)) - for (i <- initsz until secondsz) assert(ct.putIfAbsent(new DumbHash(i), i) == None) - for (i <- initsz until secondsz) assert(ct.lookup(new DumbHash(i)) == i) - } - - "replace elements with the same hash codes" in { - val ct = new TrieMap[DumbHash, Int] - for (i <- 0 until initsz) assert(ct.put(new DumbHash(i), i) == None) - for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == i) - for (i <- 0 until initsz) assert(ct.replace(new DumbHash(i), -i) == Some(i)) - for (i <- 0 until initsz) assert(ct.lookup(new DumbHash(i)) == -i) - for (i <- 0 until initsz) assert(ct.replace(new DumbHash(i), -i, i) == true) - } - - "remove elements with the same hash codes if mapped to a specific value" in { - val ct = new TrieMap[DumbHash, Int] - for (i <- 0 until initsz) assert(ct.put(new DumbHash(i), i) == None) - for (i <- 0 until initsz) assert(ct.remove(new DumbHash(i), i) == true) - } - - } - -} diff --git a/test/files/run/ctries/main.scala b/test/files/run/ctries/main.scala deleted file mode 100644 index 8db7fcef54..0000000000 --- a/test/files/run/ctries/main.scala +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - -object Test { - - def main(args: Array[String]) { - ConcurrentMapSpec.test() - IteratorSpec.test() - LNodeSpec.test() - SnapshotSpec.test() - } - -} - - -trait Spec { - - implicit def str2ops(s: String) = new { - def in[U](body: =>U) { - // just execute body - body - } - } - - implicit def any2ops(a: Any) = new { - def shouldEqual(other: Any) = assert(a == other) - } - - def evaluating[U](body: =>U) = new { - def shouldProduce[T <: Throwable: ClassManifest]() = { - var produced = false - try body - catch { - case e => if (e.getClass == implicitly[ClassManifest[T]].erasure) produced = true - } finally { - assert(produced, "Did not produce exception of type: " + implicitly[ClassManifest[T]]) - } - } - } - -} diff --git a/test/files/run/ctries/snapshot.scala b/test/files/run/ctries/snapshot.scala deleted file mode 100644 index 5fe77d445b..0000000000 --- a/test/files/run/ctries/snapshot.scala +++ /dev/null @@ -1,267 +0,0 @@ - - - - -import collection._ -import collection.concurrent.TrieMap - - - -object SnapshotSpec extends Spec { - - def test() { - "support snapshots" in { - val ctn = new TrieMap - ctn.snapshot() - ctn.readOnlySnapshot() - - val ct = new TrieMap[Int, Int] - for (i <- 0 until 100) ct.put(i, i) - ct.snapshot() - ct.readOnlySnapshot() - } - - "empty 2 quiescent snapshots in isolation" in { - val sz = 4000 - - class Worker(trie: TrieMap[Wrap, Int]) extends Thread { - override def run() { - for (i <- 0 until sz) { - assert(trie.remove(new Wrap(i)) == Some(i)) - for (j <- 0 until sz) - if (j <= i) assert(trie.get(new Wrap(j)) == None) - else assert(trie.get(new Wrap(j)) == Some(j)) - } - } - } - - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct.put(new Wrap(i), i) - val snapt = ct.snapshot() - - val original = new Worker(ct) - val snapshot = new Worker(snapt) - original.start() - snapshot.start() - original.join() - snapshot.join() - - for (i <- 0 until sz) { - assert(ct.get(new Wrap(i)) == None) - assert(snapt.get(new Wrap(i)) == None) - } - } - - def consistentReadOnly(name: String, readonly: Map[Wrap, Int], sz: Int, N: Int) { - @volatile var e: Exception = null - - // reads possible entries once and stores them - // then reads all these N more times to check if the - // state stayed the same - class Reader(trie: Map[Wrap, Int]) extends Thread { - setName("Reader " + name) - - override def run() = - try check() - catch { - case ex: Exception => e = ex - } - - def check() { - val initial = mutable.Map[Wrap, Int]() - for (i <- 0 until sz) trie.get(new Wrap(i)) match { - case Some(i) => initial.put(new Wrap(i), i) - case None => // do nothing - } - - for (k <- 0 until N) { - for (i <- 0 until sz) { - val tres = trie.get(new Wrap(i)) - val ires = initial.get(new Wrap(i)) - if (tres != ires) println(i, "initially: " + ires, "traversal %d: %s".format(k, tres)) - assert(tres == ires) - } - } - } - } - - val reader = new Reader(readonly) - reader.start() - reader.join() - - if (e ne null) { - e.printStackTrace() - throw e - } - } - - // traverses the trie `rep` times and modifies each entry - class Modifier(trie: TrieMap[Wrap, Int], index: Int, rep: Int, sz: Int) extends Thread { - setName("Modifier %d".format(index)) - - override def run() { - for (k <- 0 until rep) { - for (i <- 0 until sz) trie.putIfAbsent(new Wrap(i), i) match { - case Some(_) => trie.remove(new Wrap(i)) - case None => // do nothing - } - } - } - } - - // removes all the elements from the trie - class Remover(trie: TrieMap[Wrap, Int], index: Int, totremovers: Int, sz: Int) extends Thread { - setName("Remover %d".format(index)) - - override def run() { - for (i <- 0 until sz) trie.remove(new Wrap((i + sz / totremovers * index) % sz)) - } - } - - "have a consistent quiescent read-only snapshot" in { - val sz = 10000 - val N = 100 - val W = 10 - - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct(new Wrap(i)) = i - val readonly = ct.readOnlySnapshot() - val threads = for (i <- 0 until W) yield new Modifier(ct, i, N, sz) - - threads.foreach(_.start()) - consistentReadOnly("qm", readonly, sz, N) - threads.foreach(_.join()) - } - - // now, we check non-quiescent snapshots, as these permit situations - // where a thread is caught in the middle of the update when a snapshot is taken - - "have a consistent non-quiescent read-only snapshot, concurrent with removes only" in { - val sz = 1250 - val W = 100 - val S = 5000 - - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct(new Wrap(i)) = i - val threads = for (i <- 0 until W) yield new Remover(ct, i, W, sz) - - threads.foreach(_.start()) - for (i <- 0 until S) consistentReadOnly("non-qr", ct.readOnlySnapshot(), sz, 5) - threads.foreach(_.join()) - } - - "have a consistent non-quiescent read-only snapshot, concurrent with modifications" in { - val sz = 1000 - val N = 7000 - val W = 10 - val S = 7000 - - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct(new Wrap(i)) = i - val threads = for (i <- 0 until W) yield new Modifier(ct, i, N, sz) - - threads.foreach(_.start()) - for (i <- 0 until S) consistentReadOnly("non-qm", ct.readOnlySnapshot(), sz, 5) - threads.foreach(_.join()) - } - - def consistentNonReadOnly(name: String, trie: TrieMap[Wrap, Int], sz: Int, N: Int) { - @volatile var e: Exception = null - - // reads possible entries once and stores them - // then reads all these N more times to check if the - // state stayed the same - class Worker extends Thread { - setName("Worker " + name) - - override def run() = - try check() - catch { - case ex: Exception => e = ex - } - - def check() { - val initial = mutable.Map[Wrap, Int]() - for (i <- 0 until sz) trie.get(new Wrap(i)) match { - case Some(i) => initial.put(new Wrap(i), i) - case None => // do nothing - } - - for (k <- 0 until N) { - // modify - for ((key, value) <- initial) { - val oldv = if (k % 2 == 0) value else -value - val newv = -oldv - trie.replace(key, oldv, newv) - } - - // check - for (i <- 0 until sz) if (initial.contains(new Wrap(i))) { - val expected = if (k % 2 == 0) -i else i - //println(trie.get(new Wrap(i))) - assert(trie.get(new Wrap(i)) == Some(expected)) - } else { - assert(trie.get(new Wrap(i)) == None) - } - } - } - } - - val worker = new Worker - worker.start() - worker.join() - - if (e ne null) { - e.printStackTrace() - throw e - } - } - - "have a consistent non-quiescent snapshot, concurrent with modifications" in { - val sz = 9000 - val N = 1000 - val W = 10 - val S = 400 - - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct(new Wrap(i)) = i - val threads = for (i <- 0 until W) yield new Modifier(ct, i, N, sz) - - threads.foreach(_.start()) - for (i <- 0 until S) { - consistentReadOnly("non-qm", ct.snapshot(), sz, 5) - consistentNonReadOnly("non-qsnap", ct.snapshot(), sz, 5) - } - threads.foreach(_.join()) - } - - "work when many concurrent snapshots are taken, concurrent with modifications" in { - val sz = 12000 - val W = 10 - val S = 10 - val modifytimes = 1200 - val snaptimes = 600 - val ct = new TrieMap[Wrap, Int] - for (i <- 0 until sz) ct(new Wrap(i)) = i - - class Snapshooter extends Thread { - setName("Snapshooter") - override def run() { - for (k <- 0 until snaptimes) { - val snap = ct.snapshot() - for (i <- 0 until sz) snap.remove(new Wrap(i)) - for (i <- 0 until sz) assert(!snap.contains(new Wrap(i))) - } - } - } - - val mods = for (i <- 0 until W) yield new Modifier(ct, i, modifytimes, sz) - val shooters = for (i <- 0 until S) yield new Snapshooter - val threads = mods ++ shooters - threads.foreach(_.start()) - threads.foreach(_.join()) - } - - } - -} diff --git a/test/files/run/existentials3-new.check b/test/files/run/existentials3-new.check new file mode 100644 index 0000000000..66674fbbd6 --- /dev/null +++ b/test/files/run/existentials3-new.check @@ -0,0 +1,24 @@ +ConcreteTypeTag[Bar.type], t=AbstractTypeRef, s= <: scala.runtime.AbstractFunction0[Bar] with Serializable{case def unapply(x$0: Bar): Boolean} with Singleton +ConcreteTypeTag[Bar], t=AbstractTypeRef, s= <: Test.ToS with Product with Serializable{def copy(): Bar} +ConcreteTypeTag[Test.ToS], t=RefinedType, s=f3 +ConcreteTypeTag[Test.ToS], t=RefinedType, s=f4 +ConcreteTypeTag[Test.ToS], t=RefinedType, s=f5 +ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 +ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 +ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with Test.ToS +ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with A with Test.ToS +TypeTag[List[Object{type T1}#T1]], t=TypeRef, s=class List +ConcreteTypeTag[List[Seq[Int]]], t=TypeRef, s=class List +ConcreteTypeTag[List[Seq[U forSome { type U <: Int }]]], t=TypeRef, s=class List +ConcreteTypeTag[Bar.type], t=AbstractTypeRef, s= <: scala.runtime.AbstractFunction0[Bar] with Serializable{case def unapply(x$0: Bar): Boolean} with Singleton +ConcreteTypeTag[Bar], t=AbstractTypeRef, s= <: Test.ToS with Product with Serializable{def copy(): Bar} +ConcreteTypeTag[Test.ToS], t=RefinedType, s=g3 +ConcreteTypeTag[Test.ToS], t=RefinedType, s=g4 +ConcreteTypeTag[Test.ToS], t=RefinedType, s=g5 +ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 +ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 +ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with Test.ToS +ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with A with Test.ToS +TypeTag[List[Object{type T1}#T1]], t=TypeRef, s=class List +ConcreteTypeTag[List[Seq[Int]]], t=TypeRef, s=class List +ConcreteTypeTag[List[Seq[U forSome { type U <: Int }]]], t=TypeRef, s=class List diff --git a/test/files/run/existentials3-new.scala b/test/files/run/existentials3-new.scala new file mode 100644 index 0000000000..32129a04c6 --- /dev/null +++ b/test/files/run/existentials3-new.scala @@ -0,0 +1,78 @@ +object Test { + trait ToS { final override def toString = getClass.getName } + + def f1 = { case class Bar() extends ToS; Bar } + def f2 = { case class Bar() extends ToS; Bar() } + def f3 = { class Bar() extends ToS; object Bar extends ToS; Bar } + def f4 = { class Bar() extends ToS; new Bar() } + def f5 = { object Bar extends ToS; Bar } + def f6 = { () => { object Bar extends ToS ; Bar } } + def f7 = { val f = { () => { object Bar extends ToS ; Bar } } ; f } + + def f8 = { trait A ; trait B extends A ; class C extends B with ToS; new C { } } + def f9 = { trait A ; trait B ; class C extends B with A with ToS; new C { } } + + def f10 = { class A { type T1 } ; List[A#T1]() } + def f11 = { abstract class A extends Seq[Int] ; List[A]() } + def f12 = { abstract class A extends Seq[U forSome { type U <: Int }] ; List[A]() } + + val g1 = { case class Bar() extends ToS; Bar } + val g2 = { case class Bar() extends ToS; Bar() } + val g3 = { class Bar() extends ToS; object Bar extends ToS; Bar } + val g4 = { class Bar() extends ToS; new Bar() } + val g5 = { object Bar extends ToS; Bar } + val g6 = { () => { object Bar extends ToS ; Bar } } + val g7 = { val f = { () => { object Bar extends ToS ; Bar } } ; f } + + val g8 = { trait A ; trait B extends A ; class C extends B with ToS; new C { } } + val g9 = { trait A ; trait B ; class C extends B with A with ToS; new C { } } + + val g10 = { class A { type T1 } ; List[A#T1]() } + val g11 = { abstract class A extends Seq[Int] ; List[A]() } + val g12 = { abstract class A extends Seq[U forSome { type U <: Int }] ; List[A]() } + + def printTag(t: TypeTag[_]) = { + val s = if (t.sym.isFreeType) t.sym.typeSignature.toString else t.sym.toString + println("%s, t=%s, s=%s".format(t, t.tpe.kind, s)) + } + def m[T: ConcreteTypeTag](x: T) = printTag(concreteTypeTag[T]) + def m2[T: TypeTag](x: T) = printTag(typeTag[T]) + + // tags do work for f10/g10 + def main(args: Array[String]): Unit = { + m(f1) + m(f2) + m(f3) + m(f4) + m(f5) + m(f6) + m(f7) + m(f8) + m(f9) + m2(f10) + m(f11) + m(f12) + m(g1) + m(g2) + m(g3) + m(g4) + m(g5) + m(g6) + m(g7) + m(g8) + m(g9) + m2(g10) + m(g11) + m(g12) + } +} + +object Misc { + trait Bippy { def bippy = "I'm Bippy!" } + object o1 { + def f1 = { trait A extends Seq[U forSome { type U <: Bippy }] ; abstract class B extends A ; trait C extends B ; (null: C) } + def f2 = f1.head.bippy + } + def g1 = o1.f1 _ + def g2 = o1.f2 _ +} diff --git a/test/files/run/existentials3.check b/test/files/run/existentials3.check deleted file mode 100644 index e2c9382ab4..0000000000 --- a/test/files/run/existentials3.check +++ /dev/null @@ -1,24 +0,0 @@ -ConcreteTypeTag[Bar.type], t=AbstractTypeRef, s= <: scala.runtime.AbstractFunction0[Bar] with Serializable{case def unapply(x$0: Bar): Boolean} with Singleton -ConcreteTypeTag[Bar], t=AbstractTypeRef, s= <: Test.ToS with Product with Serializable{def copy(): Bar} -ConcreteTypeTag[Test.ToS], t=RefinedType, s=f3 -ConcreteTypeTag[Test.ToS], t=RefinedType, s=f4 -ConcreteTypeTag[Test.ToS], t=RefinedType, s=f5 -ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 -ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 -ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with Test.ToS -ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with A with Test.ToS -TypeTag[List[Object{type T1}#T1]], t=TypeRef, s=class List -ConcreteTypeTag[List[Seq[Int]]], t=TypeRef, s=class List -ConcreteTypeTag[List[Seq[U forSome { type U <: Int }]]], t=TypeRef, s=class List -ConcreteTypeTag[Bar.type], t=AbstractTypeRef, s= <: scala.runtime.AbstractFunction0[Bar] with Serializable{case def unapply(x$0: Bar): Boolean} with Singleton -ConcreteTypeTag[Bar], t=AbstractTypeRef, s= <: Test.ToS with Product with Serializable{def copy(): Bar} -ConcreteTypeTag[Test.ToS], t=RefinedType, s=g3 -ConcreteTypeTag[Test.ToS], t=RefinedType, s=g4 -ConcreteTypeTag[Test.ToS], t=RefinedType, s=g5 -ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 -ConcreteTypeTag[() => Test.ToS], t=TypeRef, s=class Function0 -ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with Test.ToS -ConcreteTypeTag[$anon], t=AbstractTypeRef, s= <: B with A with Test.ToS -TypeTag[List[Object{type T1}#T1]], t=TypeRef, s=class List -ConcreteTypeTag[List[Seq[Int]]], t=TypeRef, s=class List -ConcreteTypeTag[List[Seq[U forSome { type U <: Int }]]], t=TypeRef, s=class List diff --git a/test/files/run/existentials3.scala b/test/files/run/existentials3.scala deleted file mode 100644 index d6d5612687..0000000000 --- a/test/files/run/existentials3.scala +++ /dev/null @@ -1,79 +0,0 @@ -object Test { - trait ToS { final override def toString = getClass.getName } - - def f1 = { case class Bar() extends ToS; Bar } - def f2 = { case class Bar() extends ToS; Bar() } - def f3 = { class Bar() extends ToS; object Bar extends ToS; Bar } - def f4 = { class Bar() extends ToS; new Bar() } - def f5 = { object Bar extends ToS; Bar } - def f6 = { () => { object Bar extends ToS ; Bar } } - def f7 = { val f = { () => { object Bar extends ToS ; Bar } } ; f } - - def f8 = { trait A ; trait B extends A ; class C extends B with ToS; new C { } } - def f9 = { trait A ; trait B ; class C extends B with A with ToS; new C { } } - - def f10 = { class A { type T1 } ; List[A#T1]() } - def f11 = { abstract class A extends Seq[Int] ; List[A]() } - def f12 = { abstract class A extends Seq[U forSome { type U <: Int }] ; List[A]() } - - val g1 = { case class Bar() extends ToS; Bar } - val g2 = { case class Bar() extends ToS; Bar() } - val g3 = { class Bar() extends ToS; object Bar extends ToS; Bar } - val g4 = { class Bar() extends ToS; new Bar() } - val g5 = { object Bar extends ToS; Bar } - val g6 = { () => { object Bar extends ToS ; Bar } } - val g7 = { val f = { () => { object Bar extends ToS ; Bar } } ; f } - - val g8 = { trait A ; trait B extends A ; class C extends B with ToS; new C { } } - val g9 = { trait A ; trait B ; class C extends B with A with ToS; new C { } } - - val g10 = { class A { type T1 } ; List[A#T1]() } - val g11 = { abstract class A extends Seq[Int] ; List[A]() } - val g12 = { abstract class A extends Seq[U forSome { type U <: Int }] ; List[A]() } - - def printTag(t: TypeTag[_]) = { - val s = if (t.sym.isFreeType) t.sym.typeSignature.toString else t.sym.toString - println("%s, t=%s, s=%s".format(t, t.tpe.kind, s)) - } - def m[T: ConcreteTypeTag](x: T) = printTag(concreteTypeTag[T]) - def m2[T: TypeTag](x: T) = printTag(typeTag[T]) - - // manifests don't work for f10/g10 - // oh, they do now :) - def main(args: Array[String]): Unit = { - m(f1) - m(f2) - m(f3) - m(f4) - m(f5) - m(f6) - m(f7) - m(f8) - m(f9) - m2(f10) - m(f11) - m(f12) - m(g1) - m(g2) - m(g3) - m(g4) - m(g5) - m(g6) - m(g7) - m(g8) - m(g9) - m2(g10) - m(g11) - m(g12) - } -} - -object Misc { - trait Bippy { def bippy = "I'm Bippy!" } - object o1 { - def f1 = { trait A extends Seq[U forSome { type U <: Bippy }] ; abstract class B extends A ; trait C extends B ; (null: C) } - def f2 = f1.head.bippy - } - def g1 = o1.f1 _ - def g2 = o1.f2 _ -} diff --git a/test/files/run/getClassTest-new.check b/test/files/run/getClassTest-new.check new file mode 100644 index 0000000000..94e86c3889 --- /dev/null +++ b/test/files/run/getClassTest-new.check @@ -0,0 +1,18 @@ +f1: java.lang.Class +f2: java.lang.Class +f3: java.lang.Class +f4: java.lang.Class +f5: java.lang.Class +f0: T +f1: class java.lang.Object +f2: class java.lang.Object +f3: class AnyRefs$A +f4: class AnyRefs$B +f5: class java.lang.Object +f6: class java.lang.Object +f7: class AnyRefs$A +f8: class AnyRefs$B +f1: java.lang.Class +f2: java.lang.Class +f3: java.lang.Class +f4: java.lang.Class diff --git a/test/files/run/getClassTest-new.scala b/test/files/run/getClassTest-new.scala new file mode 100644 index 0000000000..89778ca2d3 --- /dev/null +++ b/test/files/run/getClassTest-new.scala @@ -0,0 +1,66 @@ +class AnyVals { + def f1 = (5: Any).getClass + def f2 = (5: AnyVal).getClass + def f3 = 5.getClass + def f4 = (5: java.lang.Integer).getClass + def f5 = (5.asInstanceOf[AnyRef]).getClass + + // scalap says: + // + // def f1 : java.lang.Class[?0] forSome {type ?0} = { /* compiled code */ } + // def f2 : java.lang.Class[?0] forSome {type ?0} = { /* compiled code */ } + // def f3 : java.lang.Class[scala.Int] = { /* compiled code */ } + // def f4 : java.lang.Class[?0] forSome {type ?0 <: java.lang.Integer} = { /* compiled code */ } + // def f5 : java.lang.Class[?0] forSome {type ?0 <: scala.AnyRef} = { /* compiled code */ } + // + // java generic signature says: + // + // f1: java.lang.Class + // f2: java.lang.Class + // f3: java.lang.Class + // f4: java.lang.Class + // f5: java.lang.Class +} + +class AnyRefs { + class A + class B extends A + + def f1 = (new B: Any).getClass().newInstance() + def f2 = (new B: AnyRef).getClass().newInstance() + def f3 = (new B: A).getClass().newInstance() + def f4 = (new B: B).getClass().newInstance() + + def f0[T >: B] = (new B: T).getClass().newInstance() + + def f5 = f0[Any] + def f6 = f0[AnyRef] + def f7 = f0[A] + def f8 = f0[B] +} + +class MoreAnyRefs { + trait A + trait B + + // don't leak anon/refinements + def f1 = (new A with B { }).getClass() + def f2 = (new B with A { }).getClass() + def f3 = (new { def bippy() = 5 }).getClass() + def f4 = (new A { def bippy() = 5 }).getClass() +} + +object Test { + def returnTypes[T: ClassTag] = ( + classTag[T].erasure.getMethods.toList + filter (_.getName startsWith "f") + sortBy (_.getName) + map (m => m.getName + ": " + m.getGenericReturnType.toString) + ) + + def main(args: Array[String]): Unit = { + returnTypes[AnyVals] foreach println + returnTypes[AnyRefs] foreach println + returnTypes[MoreAnyRefs] foreach println + } +} diff --git a/test/files/run/getClassTest.check b/test/files/run/getClassTest.check deleted file mode 100644 index 94e86c3889..0000000000 --- a/test/files/run/getClassTest.check +++ /dev/null @@ -1,18 +0,0 @@ -f1: java.lang.Class -f2: java.lang.Class -f3: java.lang.Class -f4: java.lang.Class -f5: java.lang.Class -f0: T -f1: class java.lang.Object -f2: class java.lang.Object -f3: class AnyRefs$A -f4: class AnyRefs$B -f5: class java.lang.Object -f6: class java.lang.Object -f7: class AnyRefs$A -f8: class AnyRefs$B -f1: java.lang.Class -f2: java.lang.Class -f3: java.lang.Class -f4: java.lang.Class diff --git a/test/files/run/getClassTest.scala b/test/files/run/getClassTest.scala deleted file mode 100644 index 2485cd2c71..0000000000 --- a/test/files/run/getClassTest.scala +++ /dev/null @@ -1,66 +0,0 @@ -class AnyVals { - def f1 = (5: Any).getClass - def f2 = (5: AnyVal).getClass - def f3 = 5.getClass - def f4 = (5: java.lang.Integer).getClass - def f5 = (5.asInstanceOf[AnyRef]).getClass - - // scalap says: - // - // def f1 : java.lang.Class[?0] forSome {type ?0} = { /* compiled code */ } - // def f2 : java.lang.Class[?0] forSome {type ?0} = { /* compiled code */ } - // def f3 : java.lang.Class[scala.Int] = { /* compiled code */ } - // def f4 : java.lang.Class[?0] forSome {type ?0 <: java.lang.Integer} = { /* compiled code */ } - // def f5 : java.lang.Class[?0] forSome {type ?0 <: scala.AnyRef} = { /* compiled code */ } - // - // java generic signature says: - // - // f1: java.lang.Class - // f2: java.lang.Class - // f3: java.lang.Class - // f4: java.lang.Class - // f5: java.lang.Class -} - -class AnyRefs { - class A - class B extends A - - def f1 = (new B: Any).getClass().newInstance() - def f2 = (new B: AnyRef).getClass().newInstance() - def f3 = (new B: A).getClass().newInstance() - def f4 = (new B: B).getClass().newInstance() - - def f0[T >: B] = (new B: T).getClass().newInstance() - - def f5 = f0[Any] - def f6 = f0[AnyRef] - def f7 = f0[A] - def f8 = f0[B] -} - -class MoreAnyRefs { - trait A - trait B - - // don't leak anon/refinements - def f1 = (new A with B { }).getClass() - def f2 = (new B with A { }).getClass() - def f3 = (new { def bippy() = 5 }).getClass() - def f4 = (new A { def bippy() = 5 }).getClass() -} - -object Test { - def returnTypes[T: Manifest] = ( - manifest[T].erasure.getMethods.toList - filter (_.getName startsWith "f") - sortBy (_.getName) - map (m => m.getName + ": " + m.getGenericReturnType.toString) - ) - - def main(args: Array[String]): Unit = { - returnTypes[AnyVals] foreach println - returnTypes[AnyRefs] foreach println - returnTypes[MoreAnyRefs] foreach println - } -} diff --git a/test/files/run/manifests-new.scala b/test/files/run/manifests-new.scala new file mode 100644 index 0000000000..4485ce9124 --- /dev/null +++ b/test/files/run/manifests-new.scala @@ -0,0 +1,147 @@ +object Test +{ + object Variances extends Enumeration { + val CO, IN, CONTRA = Value + } + import Variances.{ CO, IN, CONTRA } + + object SubtypeRelationship extends Enumeration { + val NONE, SAME, SUB, SUPER = Value + } + import SubtypeRelationship.{ NONE, SAME, SUB, SUPER } + + class VarianceTester[T, U, CC[_]](expected: Variances.Value)( + implicit ev1: TypeTag[T], ev2: TypeTag[U], ev3: TypeTag[CC[T]], ev4: TypeTag[CC[U]]) { + + def elements = List(ev1.tpe <:< ev2.tpe, ev2.tpe <:< ev1.tpe) + def containers = List(ev3.tpe <:< ev4.tpe, ev4.tpe <:< ev3.tpe) + + def isUnrelated = typeCompare[T, U] == NONE + def isSame = typeCompare[T, U] == SAME + def isSub = typeCompare[T, U] == SUB + def isSuper = typeCompare[T, U] == SUPER + + def showsCovariance = (elements == containers) + def showsContravariance = (elements == containers.reverse) + def showsInvariance = containers forall (_ == isSame) + + def allContainerVariances = List(showsCovariance, showsInvariance, showsContravariance) + + def showsExpectedVariance = + if (isUnrelated) allContainerVariances forall (_ == false) + else if (isSame) allContainerVariances forall (_ == true) + else expected match { + case CO => showsCovariance && !showsContravariance && !showsInvariance + case IN => showsInvariance && !showsCovariance && !showsContravariance + case CONTRA => showsContravariance && !showsCovariance && !showsInvariance + } + } + + def showsCovariance[T, U, CC[_]](implicit ev1: TypeTag[T], ev2: TypeTag[U], ev3: TypeTag[CC[T]], ev4: TypeTag[CC[U]]) = + new VarianceTester[T, U, CC](CO) showsExpectedVariance + + def showsInvariance[T, U, CC[_]](implicit ev1: TypeTag[T], ev2: TypeTag[U], ev3: TypeTag[CC[T]], ev4: TypeTag[CC[U]]) = + new VarianceTester[T, U, CC](IN) showsExpectedVariance + + def showsContravariance[T, U, CC[_]](implicit ev1: TypeTag[T], ev2: TypeTag[U], ev3: TypeTag[CC[T]], ev4: TypeTag[CC[U]]) = + new VarianceTester[T, U, CC](CONTRA) showsExpectedVariance + + def typeCompare[T, U](implicit ev1: TypeTag[T], ev2: TypeTag[U]) = (ev1.tpe <:< ev2.tpe, ev2.tpe <:< ev1.tpe) match { + case (true, true) => SAME + case (true, false) => SUB + case (false, true) => SUPER + case (false, false) => NONE + } + + def assertAnyRef[T: TypeTag] = List( + typeTag[T].tpe <:< typeTag[Any].tpe, + typeTag[T].tpe <:< typeTag[AnyRef].tpe, + !(typeTag[T].tpe <:< typeTag[AnyVal].tpe) + ) foreach (assert(_, "assertAnyRef")) + + def assertAnyVal[T: TypeTag] = List( + typeTag[T].tpe <:< typeTag[Any].tpe, + !(typeTag[T].tpe <:< typeTag[AnyRef].tpe), + typeTag[T].tpe <:< typeTag[AnyVal].tpe + ) foreach (assert(_, "assertAnyVal")) + + def assertSameType[T: TypeTag, U: TypeTag] = assert(typeCompare[T, U] == SAME, "assertSameType") + def assertSuperType[T: TypeTag, U: TypeTag] = assert(typeCompare[T, U] == SUPER, "assertSuperType") + def assertSubType[T: TypeTag, U: TypeTag] = assert(typeCompare[T, U] == SUB, "assertSubType") + def assertNoRelationship[T: TypeTag, U: TypeTag] = assert(typeCompare[T, U] == NONE, "assertNoRelationship") + + def testVariancesVia[T: TypeTag, U: TypeTag] = assert( + typeCompare[T, U] == SUB && + showsCovariance[T, U, List] && + showsInvariance[T, U, Set], + "testVariancesVia" + ) + + def runAllTests = { + assertAnyVal[AnyVal] + assertAnyVal[Unit] + assertAnyVal[Int] + assertAnyVal[Double] + assertAnyVal[Boolean] + assertAnyVal[Char] + + assertAnyRef[AnyRef] + assertAnyRef[java.lang.Object] + assertAnyRef[java.lang.Integer] + assertAnyRef[java.lang.Double] + assertAnyRef[java.lang.Boolean] + assertAnyRef[java.lang.Character] + assertAnyRef[String] + assertAnyRef[scala.List[String]] + assertAnyRef[scala.List[_]] + + // variance doesn't work yet + // testVariancesVia[String, Any] + // testVariancesVia[String, AnyRef] + + assertSubType[List[String], List[Any]] + assertSubType[List[String], List[AnyRef]] + assertNoRelationship[List[String], List[AnyVal]] + + assertSubType[List[Int], List[Any]] + assertSubType[List[Int], List[AnyVal]] + assertNoRelationship[List[Int], List[AnyRef]] + + // Nothing + assertSubType[Nothing, Any] + assertSubType[Nothing, AnyVal] + assertSubType[Nothing, AnyRef] + assertSubType[Nothing, String] + assertSubType[Nothing, List[String]] + assertSubType[Nothing, Null] + assertSameType[Nothing, Nothing] + + // Null + assertSubType[Null, Any] + assertNoRelationship[Null, AnyVal] + assertSubType[Null, AnyRef] + assertSubType[Null, String] + assertSubType[Null, List[String]] + assertSameType[Null, Null] + assertSuperType[Null, Nothing] + + // Any + assertSameType[Any, Any] + assertSuperType[Any, AnyVal] + assertSuperType[Any, AnyRef] + assertSuperType[Any, String] + assertSuperType[Any, List[String]] + assertSuperType[Any, Null] + assertSuperType[Any, Nothing] + + // Misc unrelated types + assertNoRelationship[Unit, AnyRef] + assertNoRelationship[Unit, Int] + assertNoRelationship[Int, Long] + assertNoRelationship[Boolean, String] + assertNoRelationship[List[Boolean], List[String]] + assertNoRelationship[Set[Boolean], Set[String]] + } + + def main(args: Array[String]): Unit = runAllTests +} diff --git a/test/files/run/manifests.scala b/test/files/run/manifests.scala deleted file mode 100644 index 2d64bf18a9..0000000000 --- a/test/files/run/manifests.scala +++ /dev/null @@ -1,149 +0,0 @@ -object Test -{ - object Variances extends Enumeration { - val CO, IN, CONTRA = Value - } - import Variances.{ CO, IN, CONTRA } - - object SubtypeRelationship extends Enumeration { - val NONE, SAME, SUB, SUPER = Value - } - import SubtypeRelationship.{ NONE, SAME, SUB, SUPER } - - class VarianceTester[T, U, CC[_]](expected: Variances.Value)( - implicit ev1: Manifest[T], ev2: Manifest[U], ev3: Manifest[CC[T]], ev4: Manifest[CC[U]]) { - - def elements = List(ev1.tpe <:< ev2.tpe, ev2.tpe <:< ev1.tpe) - def containers = List(ev3.tpe <:< ev4.tpe, ev4.tpe <:< ev3.tpe) - - def isUnrelated = typeCompare[T, U] == NONE - def isSame = typeCompare[T, U] == SAME - def isSub = typeCompare[T, U] == SUB - def isSuper = typeCompare[T, U] == SUPER - - def showsCovariance = (elements == containers) - def showsContravariance = (elements == containers.reverse) - def showsInvariance = containers forall (_ == isSame) - - def allContainerVariances = List(showsCovariance, showsInvariance, showsContravariance) - - def showsExpectedVariance = - if (isUnrelated) allContainerVariances forall (_ == false) - else if (isSame) allContainerVariances forall (_ == true) - else expected match { - case CO => showsCovariance && !showsContravariance && !showsInvariance - case IN => showsInvariance && !showsCovariance && !showsContravariance - case CONTRA => showsContravariance && !showsCovariance && !showsInvariance - } - } - - def showsCovariance[T, U, CC[_]](implicit ev1: Manifest[T], ev2: Manifest[U], ev3: Manifest[CC[T]], ev4: Manifest[CC[U]]) = - new VarianceTester[T, U, CC](CO) showsExpectedVariance - - def showsInvariance[T, U, CC[_]](implicit ev1: Manifest[T], ev2: Manifest[U], ev3: Manifest[CC[T]], ev4: Manifest[CC[U]]) = - new VarianceTester[T, U, CC](IN) showsExpectedVariance - - def showsContravariance[T, U, CC[_]](implicit ev1: Manifest[T], ev2: Manifest[U], ev3: Manifest[CC[T]], ev4: Manifest[CC[U]]) = - new VarianceTester[T, U, CC](CONTRA) showsExpectedVariance - - def typeCompare[T, U](implicit ev1: Manifest[T], ev2: Manifest[U]) = { - (ev1.tpe <:< ev2.tpe, ev2.tpe <:< ev1.tpe) match { - case (true, true) => SAME - case (true, false) => SUB - case (false, true) => SUPER - case (false, false) => NONE - } - } - - def assertAnyRef[T: Manifest] = List( - manifest[T].tpe <:< manifest[Any].tpe, - manifest[T].tpe <:< manifest[AnyRef].tpe, - !(manifest[T].tpe <:< manifest[AnyVal].tpe) - ) foreach (assert(_, "assertAnyRef")) - - def assertAnyVal[T: Manifest] = List( - manifest[T].tpe <:< manifest[Any].tpe, - !(manifest[T].tpe <:< manifest[AnyRef].tpe), - manifest[T].tpe <:< manifest[AnyVal].tpe - ) foreach (assert(_, "assertAnyVal")) - - def assertSameType[T: Manifest, U: Manifest] = assert(typeCompare[T, U] == SAME, "assertSameType") - def assertSuperType[T: Manifest, U: Manifest] = assert(typeCompare[T, U] == SUPER, "assertSuperType") - def assertSubType[T: Manifest, U: Manifest] = assert(typeCompare[T, U] == SUB, "assertSubType") - def assertNoRelationship[T: Manifest, U: Manifest] = assert(typeCompare[T, U] == NONE, "assertNoRelationship") - - def testVariancesVia[T: Manifest, U: Manifest] = assert( - typeCompare[T, U] == SUB && - showsCovariance[T, U, List] && - showsInvariance[T, U, Set], - "testVariancesVia" - ) - - def runAllTests = { - assertAnyVal[AnyVal] - assertAnyVal[Unit] - assertAnyVal[Int] - assertAnyVal[Double] - assertAnyVal[Boolean] - assertAnyVal[Char] - - assertAnyRef[AnyRef] - assertAnyRef[java.lang.Object] - assertAnyRef[java.lang.Integer] - assertAnyRef[java.lang.Double] - assertAnyRef[java.lang.Boolean] - assertAnyRef[java.lang.Character] - assertAnyRef[String] - assertAnyRef[scala.List[String]] - assertAnyRef[scala.List[_]] - - // variance doesn't work yet - // testVariancesVia[String, Any] - // testVariancesVia[String, AnyRef] - - assertSubType[List[String], List[Any]] - assertSubType[List[String], List[AnyRef]] - assertNoRelationship[List[String], List[AnyVal]] - - assertSubType[List[Int], List[Any]] - assertSubType[List[Int], List[AnyVal]] - assertNoRelationship[List[Int], List[AnyRef]] - - // Nothing - assertSubType[Nothing, Any] - assertSubType[Nothing, AnyVal] - assertSubType[Nothing, AnyRef] - assertSubType[Nothing, String] - assertSubType[Nothing, List[String]] - assertSubType[Nothing, Null] - assertSameType[Nothing, Nothing] - - // Null - assertSubType[Null, Any] - assertNoRelationship[Null, AnyVal] - assertSubType[Null, AnyRef] - assertSubType[Null, String] - assertSubType[Null, List[String]] - assertSameType[Null, Null] - assertSuperType[Null, Nothing] - - // Any - assertSameType[Any, Any] - assertSuperType[Any, AnyVal] - assertSuperType[Any, AnyRef] - assertSuperType[Any, String] - assertSuperType[Any, List[String]] - assertSuperType[Any, Null] - assertSuperType[Any, Nothing] - - // Misc unrelated types - assertNoRelationship[Unit, AnyRef] - assertNoRelationship[Unit, Int] - assertNoRelationship[Int, Long] - assertNoRelationship[Boolean, String] - assertNoRelationship[List[Boolean], List[String]] - assertNoRelationship[Set[Boolean], Set[String]] - } - - def main(args: Array[String]): Unit = runAllTests -} diff --git a/test/files/run/patmat_unapp_abstype-new.check b/test/files/run/patmat_unapp_abstype-new.check new file mode 100644 index 0000000000..72239d16cd --- /dev/null +++ b/test/files/run/patmat_unapp_abstype-new.check @@ -0,0 +1,4 @@ +TypeRef +none of the above +Bar +Foo diff --git a/test/files/run/patmat_unapp_abstype-new.flags b/test/files/run/patmat_unapp_abstype-new.flags new file mode 100644 index 0000000000..ba80cad69b --- /dev/null +++ b/test/files/run/patmat_unapp_abstype-new.flags @@ -0,0 +1 @@ +-Xoldpatmat diff --git a/test/files/run/patmat_unapp_abstype-new.scala b/test/files/run/patmat_unapp_abstype-new.scala new file mode 100644 index 0000000000..45496f08a2 --- /dev/null +++ b/test/files/run/patmat_unapp_abstype-new.scala @@ -0,0 +1,83 @@ +// abstract types and extractors, oh my! +trait TypesAPI { + trait Type + + // an alternative fix (implemented in the virtual pattern matcher, is to replace the isInstanceOf by a manifest-based run-time test) + // that's what typeRefMani is for + type TypeRef <: Type //; implicit def typeRefMani: Manifest[TypeRef] + val TypeRef: TypeRefExtractor; trait TypeRefExtractor { + def apply(x: Int): TypeRef + def unapply(x: TypeRef): Option[(Int)] + } + + // just for illustration, should follow the same pattern as TypeRef + case class MethodType(n: Int) extends Type +} + +// user should not be exposed to the implementation +trait TypesUser extends TypesAPI { + def shouldNotCrash(tp: Type): Unit = { + tp match { + case TypeRef(x) => println("TypeRef") + // the above checks tp.isInstanceOf[TypeRef], which is erased to tp.isInstanceOf[Type] + // before calling TypeRef.unapply(tp), which will then crash unless tp.isInstanceOf[TypesImpl#TypeRef] (which is not implied by tp.isInstanceOf[Type]) + // tp.isInstanceOf[TypesImpl#TypeRef] is equivalent to classOf[TypesImpl#TypeRef].isAssignableFrom(tp.getClass) + // this is equivalent to manifest + // it is NOT equivalent to manifest[Type] <:< typeRefMani + case MethodType(x) => println("MethodType") + case _ => println("none of the above") + } + } +} + +trait TypesImpl extends TypesAPI { + object TypeRef extends TypeRefExtractor // this will have a bridged unapply(x: Type) = unapply(x.asInstanceOf[TypeRef]) + case class TypeRef(n: Int) extends Type // this has a bridge from TypesAPI#Type to TypesImpl#TypeRef + // --> the cast in the bridge will fail because the pattern matcher can't type test against the abstract types in TypesUser + //lazy val typeRefMani = manifest[TypeRef] +} + +trait Foos { + trait Bar + type Foo <: Bar + trait FooExtractor { + def unapply(foo: Foo): Option[Int] + } + val Foo: FooExtractor +} + +trait RealFoos extends Foos { + class Foo(val x: Int) extends Bar + object Foo extends FooExtractor { + def unapply(foo: Foo): Option[Int] = Some(foo.x) + } +} + +trait Intermed extends Foos { + def crash(bar: Bar): Unit = + bar match { + case Foo(x) => println("Foo") + case _ => println("Bar") + } +} + +object TestUnappStaticallyKnownSynthetic extends TypesImpl with TypesUser { + def test() = { + shouldNotCrash(TypeRef(10)) // should and does print "TypeRef" + // once #1697/#2337 are fixed, this should generate the correct output + shouldNotCrash(MethodType(10)) // should print "MethodType" but prints "none of the above" -- good one, pattern matcher! + } +} + +object TestUnappDynamicSynth extends RealFoos with Intermed { + case class FooToo(n: Int) extends Bar + def test() = { + crash(FooToo(10)) + crash(new Foo(5)) + } +} + +object Test extends App { + TestUnappStaticallyKnownSynthetic.test() + TestUnappDynamicSynth.test() +} diff --git a/test/files/run/patmat_unapp_abstype.check b/test/files/run/patmat_unapp_abstype.check deleted file mode 100644 index 72239d16cd..0000000000 --- a/test/files/run/patmat_unapp_abstype.check +++ /dev/null @@ -1,4 +0,0 @@ -TypeRef -none of the above -Bar -Foo diff --git a/test/files/run/patmat_unapp_abstype.flags b/test/files/run/patmat_unapp_abstype.flags deleted file mode 100644 index ba80cad69b..0000000000 --- a/test/files/run/patmat_unapp_abstype.flags +++ /dev/null @@ -1 +0,0 @@ --Xoldpatmat diff --git a/test/files/run/patmat_unapp_abstype.scala b/test/files/run/patmat_unapp_abstype.scala deleted file mode 100644 index 45496f08a2..0000000000 --- a/test/files/run/patmat_unapp_abstype.scala +++ /dev/null @@ -1,83 +0,0 @@ -// abstract types and extractors, oh my! -trait TypesAPI { - trait Type - - // an alternative fix (implemented in the virtual pattern matcher, is to replace the isInstanceOf by a manifest-based run-time test) - // that's what typeRefMani is for - type TypeRef <: Type //; implicit def typeRefMani: Manifest[TypeRef] - val TypeRef: TypeRefExtractor; trait TypeRefExtractor { - def apply(x: Int): TypeRef - def unapply(x: TypeRef): Option[(Int)] - } - - // just for illustration, should follow the same pattern as TypeRef - case class MethodType(n: Int) extends Type -} - -// user should not be exposed to the implementation -trait TypesUser extends TypesAPI { - def shouldNotCrash(tp: Type): Unit = { - tp match { - case TypeRef(x) => println("TypeRef") - // the above checks tp.isInstanceOf[TypeRef], which is erased to tp.isInstanceOf[Type] - // before calling TypeRef.unapply(tp), which will then crash unless tp.isInstanceOf[TypesImpl#TypeRef] (which is not implied by tp.isInstanceOf[Type]) - // tp.isInstanceOf[TypesImpl#TypeRef] is equivalent to classOf[TypesImpl#TypeRef].isAssignableFrom(tp.getClass) - // this is equivalent to manifest - // it is NOT equivalent to manifest[Type] <:< typeRefMani - case MethodType(x) => println("MethodType") - case _ => println("none of the above") - } - } -} - -trait TypesImpl extends TypesAPI { - object TypeRef extends TypeRefExtractor // this will have a bridged unapply(x: Type) = unapply(x.asInstanceOf[TypeRef]) - case class TypeRef(n: Int) extends Type // this has a bridge from TypesAPI#Type to TypesImpl#TypeRef - // --> the cast in the bridge will fail because the pattern matcher can't type test against the abstract types in TypesUser - //lazy val typeRefMani = manifest[TypeRef] -} - -trait Foos { - trait Bar - type Foo <: Bar - trait FooExtractor { - def unapply(foo: Foo): Option[Int] - } - val Foo: FooExtractor -} - -trait RealFoos extends Foos { - class Foo(val x: Int) extends Bar - object Foo extends FooExtractor { - def unapply(foo: Foo): Option[Int] = Some(foo.x) - } -} - -trait Intermed extends Foos { - def crash(bar: Bar): Unit = - bar match { - case Foo(x) => println("Foo") - case _ => println("Bar") - } -} - -object TestUnappStaticallyKnownSynthetic extends TypesImpl with TypesUser { - def test() = { - shouldNotCrash(TypeRef(10)) // should and does print "TypeRef" - // once #1697/#2337 are fixed, this should generate the correct output - shouldNotCrash(MethodType(10)) // should print "MethodType" but prints "none of the above" -- good one, pattern matcher! - } -} - -object TestUnappDynamicSynth extends RealFoos with Intermed { - case class FooToo(n: Int) extends Bar - def test() = { - crash(FooToo(10)) - crash(new Foo(5)) - } -} - -object Test extends App { - TestUnappStaticallyKnownSynthetic.test() - TestUnappDynamicSynth.test() -} diff --git a/test/files/run/primitive-sigs-2-new.check b/test/files/run/primitive-sigs-2-new.check new file mode 100644 index 0000000000..b82ddbeaff --- /dev/null +++ b/test/files/run/primitive-sigs-2-new.check @@ -0,0 +1,7 @@ +T +List(A, char, class java.lang.Object) +a +public java.lang.Object Arr.arr4(java.lang.Object[],scala.reflect.ArrayTag) +public float[] Arr.arr3(float[][]) +public scala.collection.immutable.List Arr.arr2(java.lang.Character[]) +public scala.collection.immutable.List Arr.arr1(int[]) diff --git a/test/files/run/primitive-sigs-2-new.scala b/test/files/run/primitive-sigs-2-new.scala new file mode 100644 index 0000000000..7e13014cb2 --- /dev/null +++ b/test/files/run/primitive-sigs-2-new.scala @@ -0,0 +1,31 @@ +import java.{ lang => jl } + +trait T[A] { + def f(): A +} +class C extends T[Char] { + def f(): Char = 'a' +} +class Arr { + def arr1(xs: Array[Int]): List[Int] = xs.toList + def arr2(xs: Array[jl.Character]): List[jl.Character] = xs.toList + def arr3(xss: Array[Array[Float]]): Array[Float] = xss map (_.sum) + def arr4[T: ArrayTag](xss: Array[Array[T]]): Array[T] = xss map (_.head) +} + +object Test { + val c1: Class[_] = classOf[T[_]] + val c2: Class[_] = classOf[C] + val c3: Class[_] = classOf[Arr] + + val c1m = c1.getMethods.toList filter (_.getName == "f") map (_.getGenericReturnType.toString) + val c2m = c2.getMethods.toList filter (_.getName == "f") map (_.getGenericReturnType.toString) + val c3m = c3.getDeclaredMethods.toList map (_.toGenericString) + + def main(args: Array[String]): Unit = { + println(c2.getGenericInterfaces.map(_.toString).sorted mkString " ") + println(c1m ++ c2m sorted) + println(new C f) + c3m.sorted foreach println + } +} diff --git a/test/files/run/primitive-sigs-2.check b/test/files/run/primitive-sigs-2.check deleted file mode 100644 index 1b6e24ed20..0000000000 --- a/test/files/run/primitive-sigs-2.check +++ /dev/null @@ -1,7 +0,0 @@ -T -List(A, char, class java.lang.Object) -a -public java.lang.Object Arr.arr4(java.lang.Object[],scala.reflect.api.TypeTags.scala.reflect.api.TypeTags$ConcreteTypeTag) -public float[] Arr.arr3(float[][]) -public scala.collection.immutable.List Arr.arr2(java.lang.Character[]) -public scala.collection.immutable.List Arr.arr1(int[]) diff --git a/test/files/run/primitive-sigs-2.scala b/test/files/run/primitive-sigs-2.scala deleted file mode 100644 index b7152f7e3d..0000000000 --- a/test/files/run/primitive-sigs-2.scala +++ /dev/null @@ -1,39 +0,0 @@ -import java.{ lang => jl } - -trait T[A] { - def f(): A -} -class C extends T[Char] { - def f(): Char = 'a' -} -class Arr { - def arr1(xs: Array[Int]): List[Int] = xs.toList - def arr2(xs: Array[jl.Character]): List[jl.Character] = xs.toList - def arr3(xss: Array[Array[Float]]): Array[Float] = xss map (_.sum) - // This gets a signature like - // public java.lang.Object Arr.arr4(java.lang.Object[],scala.reflect.Manifest) - // - // instead of the more appealing version from the past - // public T[] Arr.arr4(T[][],scala.reflect.Manifest) - // - // because java inflict's its reference-only generic-arrays on us. - // - def arr4[T: Manifest](xss: Array[Array[T]]): Array[T] = xss map (_.head) -} - -object Test { - val c1: Class[_] = classOf[T[_]] - val c2: Class[_] = classOf[C] - val c3: Class[_] = classOf[Arr] - - val c1m = c1.getMethods.toList filter (_.getName == "f") map (_.getGenericReturnType.toString) - val c2m = c2.getMethods.toList filter (_.getName == "f") map (_.getGenericReturnType.toString) - val c3m = c3.getDeclaredMethods.toList map (_.toGenericString) - - def main(args: Array[String]): Unit = { - println(c2.getGenericInterfaces.map(_.toString).sorted mkString " ") - println(c1m ++ c2m sorted) - println(new C f) - c3m.sorted foreach println - } -} diff --git a/test/files/run/reflection-implClass-new.scala b/test/files/run/reflection-implClass-new.scala new file mode 100644 index 0000000000..27374f2106 --- /dev/null +++ b/test/files/run/reflection-implClass-new.scala @@ -0,0 +1,38 @@ +/** + * Tries to load a symbol for the `Foo$class` using Scala reflection. + * Since trait implementation classes do not get pickling information + * symbol for them should be created using fallback mechanism + * that exposes Java reflection information dressed up in + * a Scala symbol. + */ +object Test extends App with Outer { + import scala.reflect.mirror + + assert(mirror.classToSymbol(classTag[Foo].erasure).typeSignature.declaration(mirror.newTermName("bar")).typeSignature == + mirror.classToSymbol(classTag[Bar].erasure).typeSignature.declaration(mirror.newTermName("foo")).typeSignature) + + val s1 = implClass(classTag[Foo].erasure) + assert(s1 != mirror.NoSymbol) + assert(s1.typeSignature != mirror.NoType) + assert(s1.companionSymbol.typeSignature != mirror.NoType) + assert(s1.companionSymbol.typeSignature.declaration(mirror.newTermName("bar")) != mirror.NoSymbol) + val s2 = implClass(classTag[Bar].erasure) + assert(s2 != mirror.NoSymbol) + assert(s2.typeSignature != mirror.NoType) + assert(s2.companionSymbol.typeSignature != mirror.NoType) + assert(s2.companionSymbol.typeSignature.declaration(mirror.newTermName("foo")) != mirror.NoSymbol) + def implClass(clazz: Class[_]) = { + val implClass = Class.forName(clazz.getName + "$class") + mirror.classToSymbol(implClass) + } +} + +trait Foo { + def bar = 1 +} + +trait Outer { + trait Bar { + def foo = 1 + } +} diff --git a/test/files/run/reflection-implClass.scala b/test/files/run/reflection-implClass.scala deleted file mode 100644 index 7718b52f33..0000000000 --- a/test/files/run/reflection-implClass.scala +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Tries to load a symbol for the `Foo$class` using Scala reflection. - * Since trait implementation classes do not get pickling information - * symbol for them should be created using fallback mechanism - * that exposes Java reflection information dressed up in - * a Scala symbol. - */ -object Test extends App with Outer { - import scala.reflect.mirror - - assert(mirror.classToSymbol(manifest[Foo].erasure).typeSignature.declaration(mirror.newTermName("bar")).typeSignature == - mirror.classToSymbol(manifest[Bar].erasure).typeSignature.declaration(mirror.newTermName("foo")).typeSignature) - - val s1 = implClass(manifest[Foo].erasure) - assert(s1 != mirror.NoSymbol) - assert(s1.typeSignature != mirror.NoType) - assert(s1.companionSymbol.typeSignature != mirror.NoType) - assert(s1.companionSymbol.typeSignature.declaration(mirror.newTermName("bar")) != mirror.NoSymbol) - val s2 = implClass(manifest[Bar].erasure) - assert(s2 != mirror.NoSymbol) - assert(s2.typeSignature != mirror.NoType) - assert(s2.companionSymbol.typeSignature != mirror.NoType) - assert(s2.companionSymbol.typeSignature.declaration(mirror.newTermName("foo")) != mirror.NoSymbol) - def implClass(clazz: Class[_]) = { - val implClass = Class.forName(clazz.getName + "$class") - mirror.classToSymbol(implClass) - } -} - -trait Foo { - def bar = 1 -} - -trait Outer { - trait Bar { - def foo = 1 - } -} diff --git a/test/files/run/reify_implicits-new.check b/test/files/run/reify_implicits-new.check new file mode 100644 index 0000000000..e3aeb20f6b --- /dev/null +++ b/test/files/run/reify_implicits-new.check @@ -0,0 +1 @@ +x = List(1, 2, 3, 4) diff --git a/test/files/run/reify_implicits-new.scala b/test/files/run/reify_implicits-new.scala new file mode 100644 index 0000000000..69198391d1 --- /dev/null +++ b/test/files/run/reify_implicits-new.scala @@ -0,0 +1,14 @@ +import scala.reflect.mirror._ + +object Test extends App { + reify { + implicit def arrayWrapper[A : ArrayTag](x: Array[A]) = + new { + def sort(p: (A, A) => Boolean) = { + util.Sorting.stableSort(x, p); x + } + } + val x = Array(2, 3, 1, 4) + println("x = "+ x.sort((x: Int, y: Int) => x < y).toList) + }.eval +} diff --git a/test/files/run/reify_implicits.check b/test/files/run/reify_implicits.check deleted file mode 100644 index e3aeb20f6b..0000000000 --- a/test/files/run/reify_implicits.check +++ /dev/null @@ -1 +0,0 @@ -x = List(1, 2, 3, 4) diff --git a/test/files/run/reify_implicits.scala b/test/files/run/reify_implicits.scala deleted file mode 100644 index 60971c3cfb..0000000000 --- a/test/files/run/reify_implicits.scala +++ /dev/null @@ -1,14 +0,0 @@ -import scala.reflect.mirror._ - -object Test extends App { - reify { - implicit def arrayWrapper[A : ClassManifest](x: Array[A]) = - new { - def sort(p: (A, A) => Boolean) = { - util.Sorting.stableSort(x, p); x - } - } - val x = Array(2, 3, 1, 4) - println("x = "+ x.sort((x: Int, y: Int) => x < y).toList) - }.eval -} diff --git a/test/files/run/repl-power.check b/test/files/run/repl-power.check index 1e7b6f0cd8..c509434116 100644 --- a/test/files/run/repl-power.check +++ b/test/files/run/repl-power.check @@ -1,32 +1,32 @@ -Type in expressions to have them evaluated. -Type :help for more information. - -scala> :power -** Power User mode enabled - BEEP WHIR GYVE ** -** :phase has been set to 'typer'. ** -** scala.tools.nsc._ has been imported ** -** global._, definitions._ also imported ** -** Try :help, :vals, power. ** - -scala> // guarding against "error: reference to global is ambiguous" - -scala> global.emptyValDef // "it is imported twice in the same scope by ..." -res0: $r.global.emptyValDef.type = private val _ = _ - -scala> val tp = ArrayClass[scala.util.Random] // magic with manifests -tp: $r.global.Type = Array[scala.util.Random] - -scala> tp.memberType(Array_apply) // evidence -res1: $r.global.Type = (i: Int)scala.util.Random - -scala> val m = LIT(10) MATCH (CASE(LIT(5)) ==> FALSE, DEFAULT ==> TRUE) // treedsl -m: $r.treedsl.global.Match = -10 match { - case 5 => false - case _ => true -} - -scala> typed(m).tpe // typed is in scope -res2: $r.treedsl.global.Type = Boolean - -scala> +Type in expressions to have them evaluated. +Type :help for more information. + +scala> :power +** Power User mode enabled - BEEP WHIR GYVE ** +** :phase has been set to 'typer'. ** +** scala.tools.nsc._ has been imported ** +** global._, definitions._ also imported ** +** Try :help, :vals, power. ** + +scala> // guarding against "error: reference to global is ambiguous" + +scala> global.emptyValDef // "it is imported twice in the same scope by ..." +res0: $r.global.emptyValDef.type = private val _ = _ + +scala> val tp = ArrayClass[scala.util.Random] // magic with tags +tp: $r.global.Type = Array[scala.util.Random] + +scala> tp.memberType(Array_apply) // evidence +res1: $r.global.Type = (i: Int)scala.util.Random + +scala> val m = LIT(10) MATCH (CASE(LIT(5)) ==> FALSE, DEFAULT ==> TRUE) // treedsl +m: $r.treedsl.global.Match = +10 match { + case 5 => false + case _ => true +} + +scala> typed(m).tpe // typed is in scope +res2: $r.treedsl.global.Type = Boolean + +scala> diff --git a/test/files/run/repl-power.scala b/test/files/run/repl-power.scala index 27da3df106..f7c88c63ff 100644 --- a/test/files/run/repl-power.scala +++ b/test/files/run/repl-power.scala @@ -5,10 +5,9 @@ object Test extends ReplTest { :power // guarding against "error: reference to global is ambiguous" global.emptyValDef // "it is imported twice in the same scope by ..." -val tp = ArrayClass[scala.util.Random] // magic with manifests +val tp = ArrayClass[scala.util.Random] // magic with tags tp.memberType(Array_apply) // evidence val m = LIT(10) MATCH (CASE(LIT(5)) ==> FALSE, DEFAULT ==> TRUE) // treedsl typed(m).tpe // typed is in scope """.trim } - diff --git a/test/files/run/t0421-new.check b/test/files/run/t0421-new.check new file mode 100644 index 0000000000..cdcf042f19 --- /dev/null +++ b/test/files/run/t0421-new.check @@ -0,0 +1,3 @@ +[Array(0, 1),Array(2, 3),Array(4, 5)] +[Array(31.0)] +[Array(24.0, 32.0)] diff --git a/test/files/run/t0421-new.scala b/test/files/run/t0421-new.scala new file mode 100644 index 0000000000..7de6b7f2c4 --- /dev/null +++ b/test/files/run/t0421-new.scala @@ -0,0 +1,30 @@ +// ticket #421 +object Test extends App { + + def transpose[A: ArrayTag](xss: Array[Array[A]]) = { + for (i <- Array.range(0, xss(0).length)) yield + for (xs <- xss) yield xs(i) + } + + def scalprod(xs: Array[Double], ys: Array[Double]) = { + var acc = 0.0 + for ((x, y) <- xs zip ys) acc = acc + x * y + acc + } + + def matmul(xss: Array[Array[Double]], yss: Array[Array[Double]]) = { + val ysst = transpose(yss) + val ysst1: Array[Array[Double]] = yss.transpose + assert(ysst.deep == ysst1.deep) + for (xs <- xss) yield + for (yst <- ysst) yield + scalprod(xs, yst) + } + + val a1 = Array(Array(0, 2, 4), Array(1, 3, 5)) + println(transpose(a1).deep.mkString("[", ",", "]")) + + println(matmul(Array(Array(2, 3)), Array(Array(5), Array(7))).deep.mkString("[", ",", "]")) + + println(matmul(Array(Array(4)), Array(Array(6, 8))).deep.mkString("[", ",", "]")) +} diff --git a/test/files/run/t0421.check b/test/files/run/t0421.check deleted file mode 100644 index cdcf042f19..0000000000 --- a/test/files/run/t0421.check +++ /dev/null @@ -1,3 +0,0 @@ -[Array(0, 1),Array(2, 3),Array(4, 5)] -[Array(31.0)] -[Array(24.0, 32.0)] diff --git a/test/files/run/t0421.scala b/test/files/run/t0421.scala deleted file mode 100644 index 8d51013924..0000000000 --- a/test/files/run/t0421.scala +++ /dev/null @@ -1,30 +0,0 @@ -// ticket #421 -object Test extends App { - - def transpose[A: ClassManifest](xss: Array[Array[A]]) = { - for (i <- Array.range(0, xss(0).length)) yield - for (xs <- xss) yield xs(i) - } - - def scalprod(xs: Array[Double], ys: Array[Double]) = { - var acc = 0.0 - for ((x, y) <- xs zip ys) acc = acc + x * y - acc - } - - def matmul(xss: Array[Array[Double]], yss: Array[Array[Double]]) = { - val ysst = transpose(yss) - val ysst1: Array[Array[Double]] = yss.transpose - assert(ysst.deep == ysst1.deep) - for (xs <- xss) yield - for (yst <- ysst) yield - scalprod(xs, yst) - } - - val a1 = Array(Array(0, 2, 4), Array(1, 3, 5)) - println(transpose(a1).deep.mkString("[", ",", "]")) - - println(matmul(Array(Array(2, 3)), Array(Array(5), Array(7))).deep.mkString("[", ",", "]")) - - println(matmul(Array(Array(4)), Array(Array(6, 8))).deep.mkString("[", ",", "]")) -} diff --git a/test/files/run/t0677-new.scala b/test/files/run/t0677-new.scala new file mode 100644 index 0000000000..bf7a3971dc --- /dev/null +++ b/test/files/run/t0677-new.scala @@ -0,0 +1,8 @@ +object Test extends App { + class X[T: ArrayTag] { + val a = Array.ofDim[T](3, 4) + } + val x = new X[String] + x.a(1)(2) = "hello" + assert(x.a(1)(2) == "hello") +} diff --git a/test/files/run/t0677.scala b/test/files/run/t0677.scala deleted file mode 100644 index 6c8a3a7e99..0000000000 --- a/test/files/run/t0677.scala +++ /dev/null @@ -1,8 +0,0 @@ -object Test extends App { - class X[T: ClassManifest] { - val a = Array.ofDim[T](3, 4) - } - val x = new X[String] - x.a(1)(2) = "hello" - assert(x.a(1)(2) == "hello") -} diff --git a/test/files/run/t1195-new.check b/test/files/run/t1195-new.check new file mode 100644 index 0000000000..554e3fd03d --- /dev/null +++ b/test/files/run/t1195-new.check @@ -0,0 +1,6 @@ +ConcreteTypeTag[Bar.type], underlying = <: scala.runtime.AbstractFunction1[Int,Bar] with Serializable{case def unapply(x$0: Bar): Option[Int]} with Singleton +ConcreteTypeTag[Bar], underlying = <: Product with Serializable{val x: Int; def copy(x: Int): Bar; def copy$default$1: Int; def _1: Int} +ConcreteTypeTag[Product with Serializable], underlying = Product with Serializable +ConcreteTypeTag[Bar.type], underlying = <: scala.runtime.AbstractFunction1[Int,Bar] with Serializable{case def unapply(x$0: Bar): Option[Int]} with Singleton +ConcreteTypeTag[Bar], underlying = <: Product with Serializable{val x: Int; def copy(x: Int): Bar; def copy$default$1: Int; def _1: Int} +ConcreteTypeTag[Product with Serializable], underlying = Product with Serializable diff --git a/test/files/run/t1195-new.scala b/test/files/run/t1195-new.scala new file mode 100644 index 0000000000..6f28a4a167 --- /dev/null +++ b/test/files/run/t1195-new.scala @@ -0,0 +1,26 @@ +object Test { + def f() = { case class Bar(x: Int); Bar } + def g() = { case class Bar(x: Int); Bar(5) } + def h() = { case object Bar ; Bar } + + val f1 = f() + val g1 = g() + val h1 = h() + + def m[T: TypeTag](x: T) = println(typeTag[T] + ", underlying = " + typeTag[T].sym.typeSignature) + + def main(args: Array[String]): Unit = { + m(f) + m(g) + m(h) + m(f1) + m(g1) + m(h1) + } +} + +class A1[T] { + class B1[U] { + def f = { case class D(x: Int) extends A1[String] ; new D(5) } + } +} diff --git a/test/files/run/t1195.check b/test/files/run/t1195.check deleted file mode 100644 index 554e3fd03d..0000000000 --- a/test/files/run/t1195.check +++ /dev/null @@ -1,6 +0,0 @@ -ConcreteTypeTag[Bar.type], underlying = <: scala.runtime.AbstractFunction1[Int,Bar] with Serializable{case def unapply(x$0: Bar): Option[Int]} with Singleton -ConcreteTypeTag[Bar], underlying = <: Product with Serializable{val x: Int; def copy(x: Int): Bar; def copy$default$1: Int; def _1: Int} -ConcreteTypeTag[Product with Serializable], underlying = Product with Serializable -ConcreteTypeTag[Bar.type], underlying = <: scala.runtime.AbstractFunction1[Int,Bar] with Serializable{case def unapply(x$0: Bar): Option[Int]} with Singleton -ConcreteTypeTag[Bar], underlying = <: Product with Serializable{val x: Int; def copy(x: Int): Bar; def copy$default$1: Int; def _1: Int} -ConcreteTypeTag[Product with Serializable], underlying = Product with Serializable diff --git a/test/files/run/t1195.scala b/test/files/run/t1195.scala deleted file mode 100644 index 93b1dcbd07..0000000000 --- a/test/files/run/t1195.scala +++ /dev/null @@ -1,26 +0,0 @@ -object Test { - def f() = { case class Bar(x: Int); Bar } - def g() = { case class Bar(x: Int); Bar(5) } - def h() = { case object Bar ; Bar } - - val f1 = f() - val g1 = g() - val h1 = h() - - def m[T: Manifest](x: T) = println(manifest[T] + ", underlying = " + manifest[T].sym.typeSignature) - - def main(args: Array[String]): Unit = { - m(f) - m(g) - m(h) - m(f1) - m(g1) - m(h1) - } -} - -class A1[T] { - class B1[U] { - def f = { case class D(x: Int) extends A1[String] ; new D(5) } - } -} diff --git a/test/files/run/t2236-new.scala b/test/files/run/t2236-new.scala new file mode 100644 index 0000000000..bbabe8e7d9 --- /dev/null +++ b/test/files/run/t2236-new.scala @@ -0,0 +1,17 @@ +class T[A](implicit val m:TypeTag[A]) +class Foo +class Bar extends T[Foo] +object Test extends App { + new Bar +} + +object EvidenceTest { + trait E[T] + trait A[T] { implicit val e: E[T] = null } + class B[T : E] extends A[T] { override val e = null } + + def f[T] { + implicit val e: E[T] = null + new B[T]{} + } +} diff --git a/test/files/run/t2236.scala b/test/files/run/t2236.scala deleted file mode 100755 index 64ed18c805..0000000000 --- a/test/files/run/t2236.scala +++ /dev/null @@ -1,17 +0,0 @@ -class T[A](implicit val m:Manifest[A]) -class Foo -class Bar extends T[Foo] -object Test extends App { - new Bar -} - -object EvidenceTest { - trait E[T] - trait A[T] { implicit val e: E[T] = null } - class B[T : E] extends A[T] { override val e = null } - - def f[T] { - implicit val e: E[T] = null - new B[T]{} - } -} diff --git a/test/files/run/t2386-new.check b/test/files/run/t2386-new.check new file mode 100644 index 0000000000..98e226f946 --- /dev/null +++ b/test/files/run/t2386-new.check @@ -0,0 +1,2 @@ +a(0) = Array(1, 2) +a(1) = Array("a", "b") diff --git a/test/files/run/t2386-new.scala b/test/files/run/t2386-new.scala new file mode 100644 index 0000000000..15d1859759 --- /dev/null +++ b/test/files/run/t2386-new.scala @@ -0,0 +1,5 @@ +object Test extends App { + val a = Array(Array(1, 2), Array("a","b")) + println("a(0) = Array(" + (a(0) mkString ", ") + ")") + println("a(1) = Array(" + (a(1) map (s => "\"" + s + "\"") mkString ", ") + ")") +} diff --git a/test/files/run/t3507-new.check b/test/files/run/t3507-new.check new file mode 100644 index 0000000000..6e4fa4170e --- /dev/null +++ b/test/files/run/t3507-new.check @@ -0,0 +1 @@ +ConcreteTypeTag[_1.b.c.type] diff --git a/test/files/run/t3507-new.scala b/test/files/run/t3507-new.scala new file mode 100644 index 0000000000..c7a529e8b8 --- /dev/null +++ b/test/files/run/t3507-new.scala @@ -0,0 +1,15 @@ +class A { + object b { + object c + } + def m = b.c +} + +object Test extends App { + var a: A = new A // mutable + val c /*: object _1.b.c forSome { val _1: A } */ = a.m // widening using existential + + def mani[T: TypeTag](x: T) = println(typeTag[T]) + mani/*[object _1.b.c]*/(c) // kaboom in manifestOfType / TreeGen.mkAttributedQualifier + // --> _1 is not in scope here +} \ No newline at end of file diff --git a/test/files/run/t3507.check b/test/files/run/t3507.check deleted file mode 100644 index 6e4fa4170e..0000000000 --- a/test/files/run/t3507.check +++ /dev/null @@ -1 +0,0 @@ -ConcreteTypeTag[_1.b.c.type] diff --git a/test/files/run/t3507.scala b/test/files/run/t3507.scala deleted file mode 100644 index 3cdd40a881..0000000000 --- a/test/files/run/t3507.scala +++ /dev/null @@ -1,15 +0,0 @@ -class A { - object b { - object c - } - def m = b.c -} - -object Test extends App { - var a: A = new A // mutable - val c /*: object _1.b.c forSome { val _1: A } */ = a.m // widening using existential - - def mani[T: Manifest](x: T) = println(manifest[T]) - mani/*[object _1.b.c]*/(c) // kaboom in manifestOfType / TreeGen.mkAttributedQualifier - // --> _1 is not in scope here -} \ No newline at end of file diff --git a/test/files/run/t3758.check b/test/files/run/t3758.check deleted file mode 100644 index 9c6ab655a3..0000000000 --- a/test/files/run/t3758.check +++ /dev/null @@ -1,6 +0,0 @@ -List(String) -List(Int) -List(Float) -List(String) -List(Int) -List(Float) diff --git a/test/files/run/t3758.scala b/test/files/run/t3758.scala deleted file mode 100644 index 10bfb5724b..0000000000 --- a/test/files/run/t3758.scala +++ /dev/null @@ -1,10 +0,0 @@ -object Test { - def main(args: Array[String]): Unit = { - println(classManifest[Array[String]].tpe.typeArguments) - println(classManifest[Array[Int]].tpe.typeArguments) - println(classManifest[Array[Float]].tpe.typeArguments) - println(manifest[Array[String]].tpe.typeArguments) - println(manifest[Array[Int]].tpe.typeArguments) - println(manifest[Array[Float]].tpe.typeArguments) - } -} diff --git a/test/files/run/t4110-new.check b/test/files/run/t4110-new.check new file mode 100644 index 0000000000..28f220e1fe --- /dev/null +++ b/test/files/run/t4110-new.check @@ -0,0 +1,2 @@ +ConcreteTypeTag[Test.A with Test.B] +ConcreteTypeTag[Test.A with Test.B] diff --git a/test/files/run/t4110-new.scala b/test/files/run/t4110-new.scala new file mode 100644 index 0000000000..3285b82c61 --- /dev/null +++ b/test/files/run/t4110-new.scala @@ -0,0 +1,11 @@ +object Test extends App { + def inferredType[T : TypeTag](v : T) = println(typeTag[T]) + + trait A + trait B + + inferredType(new A with B) + + val name = new A with B + inferredType(name) +} \ No newline at end of file diff --git a/test/files/run/t4110.check b/test/files/run/t4110.check deleted file mode 100644 index 28f220e1fe..0000000000 --- a/test/files/run/t4110.check +++ /dev/null @@ -1,2 +0,0 @@ -ConcreteTypeTag[Test.A with Test.B] -ConcreteTypeTag[Test.A with Test.B] diff --git a/test/files/run/t4110.scala b/test/files/run/t4110.scala deleted file mode 100644 index 4bd377b73e..0000000000 --- a/test/files/run/t4110.scala +++ /dev/null @@ -1,11 +0,0 @@ -object Test extends App { - def inferredType[T : Manifest](v : T) = println(manifest[T]) - - trait A - trait B - - inferredType(new A with B) - - val name = new A with B - inferredType(name) -} \ No newline at end of file diff --git a/test/files/scalacheck/array-new.scala b/test/files/scalacheck/array-new.scala new file mode 100644 index 0000000000..18d577ca6d --- /dev/null +++ b/test/files/scalacheck/array-new.scala @@ -0,0 +1,36 @@ +import org.scalacheck._ +import Prop._ +import Gen._ +import Arbitrary._ +import util._ +import Buildable._ +import scala.collection.mutable.ArraySeq + +object Test extends Properties("Array") { + /** At this moment the authentic scalacheck Array Builder/Arb bits are commented out. + */ + implicit def arbArray[T](implicit a: Arbitrary[T], m: ArrayTag[T]): Arbitrary[Array[T]] = + Arbitrary(containerOf[List,T](arbitrary[T]) map (_.toArray)) + + val arrGen: Gen[Array[_]] = oneOf( + arbitrary[Array[Int]], + arbitrary[Array[Array[Int]]], + arbitrary[Array[List[String]]], + arbitrary[Array[String]], + arbitrary[Array[Boolean]], + arbitrary[Array[AnyVal]] + ) + + // inspired by #1857 and #2352 + property("eq/ne") = forAll(arrGen, arrGen) { (c1, c2) => + (c1 eq c2) || (c1 ne c2) + } + + // inspired by #2299 + def smallInt = choose(1, 10) + property("ofDim") = forAll(smallInt, smallInt, smallInt) { (i1, i2, i3) => + val arr = Array.ofDim[String](i1, i2, i3) + val flattened = arr flatMap (x => x) flatMap (x => x) + flattened.length == i1 * i2 * i3 + } +} diff --git a/test/files/scalacheck/array.scala b/test/files/scalacheck/array.scala deleted file mode 100644 index f262bc6320..0000000000 --- a/test/files/scalacheck/array.scala +++ /dev/null @@ -1,37 +0,0 @@ -import org.scalacheck._ -import Prop._ -import Gen._ -import Arbitrary._ -import util._ -import Buildable._ -import scala.collection.mutable.ArraySeq - -object Test extends Properties("Array") { - /** At this moment the authentic scalacheck Array Builder/Arb bits are commented out. - */ - implicit def arbArray[T](implicit a: Arbitrary[T], m: Manifest[T]): Arbitrary[Array[T]] = - Arbitrary(containerOf[List,T](arbitrary[T]) map (_.toArray)) - - val arrGen: Gen[Array[_]] = oneOf( - arbitrary[Array[Int]], - arbitrary[Array[Array[Int]]], - arbitrary[Array[List[String]]], - arbitrary[Array[String]], - arbitrary[Array[Boolean]], - arbitrary[Array[AnyVal]] - ) - - // inspired by #1857 and #2352 - property("eq/ne") = forAll(arrGen, arrGen) { (c1, c2) => - (c1 eq c2) || (c1 ne c2) - } - - // inspired by #2299 - def smallInt = choose(1, 10) - property("ofDim") = forAll(smallInt, smallInt, smallInt) { (i1, i2, i3) => - val arr = Array.ofDim[String](i1, i2, i3) - val flattened = arr flatMap (x => x) flatMap (x => x) - flattened.length == i1 * i2 * i3 - } -} - diff --git a/test/files/specialized/spec-matrix-new.check b/test/files/specialized/spec-matrix-new.check new file mode 100644 index 0000000000..5ec3e84597 --- /dev/null +++ b/test/files/specialized/spec-matrix-new.check @@ -0,0 +1,2 @@ +251437.0 +Boxed doubles: 1 diff --git a/test/files/specialized/spec-matrix-new.scala b/test/files/specialized/spec-matrix-new.scala new file mode 100644 index 0000000000..65b46e8d48 --- /dev/null +++ b/test/files/specialized/spec-matrix-new.scala @@ -0,0 +1,80 @@ +/** Test matrix multiplication with specialization. + */ + +class Matrix[@specialized A: ArrayTag](val rows: Int, val cols: Int) { + private val arr: Array[Array[A]] = Array.ofDim[A](rows, cols) + + def apply(i: Int, j: Int): A = { + if (i < 0 || i >= rows || j < 0 || j >= cols) + throw new NoSuchElementException("Indexes out of bounds: " + (i, j)) + + arr(i)(j) + } + + def update(i: Int, j: Int, e: A) { + arr(i)(j) = e + } + + def rowsIterator: Iterator[Array[A]] = new Iterator[Array[A]] { + var idx = 0; + def hasNext = idx < rows + def next = { + idx += 1 + arr(idx - 1) + } + } +} + +object Test { + def main(args: Array[String]) { + val m = randomMatrix(200, 100) + val n = randomMatrix(100, 200) + + val p = mult(m, n) + println(p(0, 0)) + println("Boxed doubles: " + runtime.BoxesRunTime.doubleBoxCount) +// println("Boxed integers: " + runtime.BoxesRunTime.integerBoxCount) + } + + def randomMatrix(n: Int, m: Int) = { + val r = new util.Random(10) + val x = new Matrix[Double](n, m) + for (i <- 0 until n; j <- 0 until m) + x(i, j) = (r.nextInt % 1000).toDouble + x + } + + def printMatrix[Double](m: Matrix[Double]) { + for (i <- 0 until m.rows) { + for (j <- 0 until m.cols) + print("%5.3f ".format(m(i, j))) + println + } + } + + def multTag[@specialized(Int) T](m: Matrix[T], n: Matrix[T])(implicit at: ArrayTag[T], num: Numeric[T]) { + val p = new Matrix[T](m.rows, n.cols) + import num._ + + for (i <- 0 until m.rows) + for (j <- 0 until n.cols) { + var sum = num.zero + for (k <- 0 until n.rows) + sum += m(i, k) * n(k, j) + p(i, j) = sum + } + } + + def mult(m: Matrix[Double], n: Matrix[Double]) = { + val p = new Matrix[Double](m.rows, n.cols) + + for (i <- 0 until m.rows) + for (j <- 0 until n.cols) { + var sum = 0.0 + for (k <- 0 until n.rows) + sum += m(i, k) * n(k, j) + p(i, j) = sum + } + p + } +} diff --git a/test/files/specialized/spec-matrix.check b/test/files/specialized/spec-matrix.check deleted file mode 100644 index 5ec3e84597..0000000000 --- a/test/files/specialized/spec-matrix.check +++ /dev/null @@ -1,2 +0,0 @@ -251437.0 -Boxed doubles: 1 diff --git a/test/files/specialized/spec-matrix.scala b/test/files/specialized/spec-matrix.scala deleted file mode 100644 index 98735c8c03..0000000000 --- a/test/files/specialized/spec-matrix.scala +++ /dev/null @@ -1,80 +0,0 @@ -/** Test matrix multiplication with specialization. - */ - -class Matrix[@specialized A: ClassManifest](val rows: Int, val cols: Int) { - private val arr: Array[Array[A]] = Array.ofDim[A](rows, cols) - - def apply(i: Int, j: Int): A = { - if (i < 0 || i >= rows || j < 0 || j >= cols) - throw new NoSuchElementException("Indexes out of bounds: " + (i, j)) - - arr(i)(j) - } - - def update(i: Int, j: Int, e: A) { - arr(i)(j) = e - } - - def rowsIterator: Iterator[Array[A]] = new Iterator[Array[A]] { - var idx = 0; - def hasNext = idx < rows - def next = { - idx += 1 - arr(idx - 1) - } - } -} - -object Test { - def main(args: Array[String]) { - val m = randomMatrix(200, 100) - val n = randomMatrix(100, 200) - - val p = mult(m, n) - println(p(0, 0)) - println("Boxed doubles: " + runtime.BoxesRunTime.doubleBoxCount) -// println("Boxed integers: " + runtime.BoxesRunTime.integerBoxCount) - } - - def randomMatrix(n: Int, m: Int) = { - val r = new util.Random(10) - val x = new Matrix[Double](n, m) - for (i <- 0 until n; j <- 0 until m) - x(i, j) = (r.nextInt % 1000).toDouble - x - } - - def printMatrix[Double](m: Matrix[Double]) { - for (i <- 0 until m.rows) { - for (j <- 0 until m.cols) - print("%5.3f ".format(m(i, j))) - println - } - } - - def multManifest[@specialized(Int) T](m: Matrix[T], n: Matrix[T])(implicit cm: ClassManifest[T], num: Numeric[T]) { - val p = new Matrix[T](m.rows, n.cols) - import num._ - - for (i <- 0 until m.rows) - for (j <- 0 until n.cols) { - var sum = num.zero - for (k <- 0 until n.rows) - sum += m(i, k) * n(k, j) - p(i, j) = sum - } - } - - def mult(m: Matrix[Double], n: Matrix[Double]) = { - val p = new Matrix[Double](m.rows, n.cols) - - for (i <- 0 until m.rows) - for (j <- 0 until n.cols) { - var sum = 0.0 - for (k <- 0 until n.rows) - sum += m(i, k) * n(k, j) - p(i, j) = sum - } - p - } -} diff --git a/test/pending/pos/inference.scala b/test/pending/pos/inference.scala index d28d003435..3672351fca 100644 --- a/test/pending/pos/inference.scala +++ b/test/pending/pos/inference.scala @@ -1,15 +1,15 @@ // inference illuminator object Test { - class D1[T1 : Manifest, T2 <: T1 : Manifest](x: T1) { println(manifest[(T1, T2)]) } - class D2[T1 : Manifest, T2 >: T1 : Manifest](x: T1) { println(manifest[(T1, T2)]) } - class D3[+T1 : Manifest, T2 <: T1 : Manifest](x: T1) { println(manifest[(T1, T2)]) } - class D4[-T1 : Manifest, T2 >: T1 : Manifest](x: T1) { println(manifest[(T1, T2)]) } - - class E1[T1 : Manifest, T2 <: T1 : Manifest](x: D1[T1, T2]) { println(manifest[(T1, T2)]) } - class E2[T1 : Manifest, T2 >: T1 : Manifest](x: D2[T1, T2]) { println(manifest[(T1, T2)]) } - class E3[+T1 : Manifest, T2 <: T1 : Manifest](x: D3[T1, T2]) { println(manifest[(T1, T2)]) } - class E4[-T1 : Manifest, T2 >: T1 : Manifest](x: D4[T1, T2]) { println(manifest[(T1, T2)]) } - + class D1[T1 : TypeTag, T2 <: T1 : TypeTag](x: T1) { println(typeTag[(T1, T2)]) } + class D2[T1 : TypeTag, T2 >: T1 : TypeTag](x: T1) { println(typeTag[(T1, T2)]) } + class D3[+T1 : TypeTag, T2 <: T1 : TypeTag](x: T1) { println(typeTag[(T1, T2)]) } + class D4[-T1 : TypeTag, T2 >: T1 : TypeTag](x: T1) { println(typeTag[(T1, T2)]) } + + class E1[T1 : TypeTag, T2 <: T1 : TypeTag](x: D1[T1, T2]) { println(typeTag[(T1, T2)]) } + class E2[T1 : TypeTag, T2 >: T1 : TypeTag](x: D2[T1, T2]) { println(typeTag[(T1, T2)]) } + class E3[+T1 : TypeTag, T2 <: T1 : TypeTag](x: D3[T1, T2]) { println(typeTag[(T1, T2)]) } + class E4[-T1 : TypeTag, T2 >: T1 : TypeTag](x: D4[T1, T2]) { println(typeTag[(T1, T2)]) } + def main(args: Array[String]): Unit = { // WHY YOU NO LIKE NOTHING SO MUCH SCALAC? val d1 = new D1(5) diff --git a/test/pending/shootout/meteor.scala b/test/pending/shootout/meteor.scala index 2fd702753a..154695533b 100644 --- a/test/pending/shootout/meteor.scala +++ b/test/pending/shootout/meteor.scala @@ -19,7 +19,7 @@ object meteor { -// Solver.scala +// Solver.scala // import scala.collection.mutable._ final class Solver (n: Int) { @@ -29,8 +29,8 @@ final class Solver (n: Int) { private val board = new Board() - val pieces = Array( - new Piece(0), new Piece(1), new Piece(2), new Piece(3), new Piece(4), + val pieces = Array( + new Piece(0), new Piece(1), new Piece(2), new Piece(3), new Piece(4), new Piece(5), new Piece(6), new Piece(7), new Piece(8), new Piece(9) ) val unplaced = new BitSet(pieces.length) @@ -71,8 +71,8 @@ final class Solver (n: Int) { private def puzzleSolved() = { val b = board.asString - if (first == null){ - first = b; last = b + if (first == null){ + first = b; last = b } else { if (b < first){ first = b } else { if (b > last){ last = b } } } @@ -81,7 +81,7 @@ final class Solver (n: Int) { private def shouldPrune() = { board.unmark - !board.cells.forall(c => c.contiguousEmptyCells % Piece.size == 0) + !board.cells.forall(c => c.contiguousEmptyCells % Piece.size == 0) } @@ -108,8 +108,8 @@ final class Solver (n: Int) { } /* - def printPieces() = - for (i <- Iterator.range(0,Board.pieces)) pieces(i).print + def printPieces() = + for (i <- Iterator.range(0,Board.pieces)) pieces(i).print */ } @@ -126,7 +126,7 @@ object Board { val size = rows * cols } -final class Board { +final class Board { val cells = boardCells() val cellsPieceWillFill = new Array[BoardCell](Piece.size) @@ -134,9 +134,9 @@ final class Board { def unmark() = for (c <- cells) c.unmark - def asString() = - new String( cells map( - c => if (c.piece == null) '-'.toByte + def asString() = + new String( cells map( + c => if (c.piece == null) '-'.toByte else (c.piece.number + 48).toByte )) def firstEmptyCellIndex() = cells.findIndexOf(c => c.isEmpty) @@ -144,13 +144,13 @@ final class Board { def add(pieceIndex: Int, boardIndex: Int, p: Piece) = { cellCount = 0 p.unmark - + find( p.cells(pieceIndex), cells(boardIndex)) - val boardHasSpace = cellCount == Piece.size && - cellsPieceWillFill.forall(c => c.isEmpty) + val boardHasSpace = cellCount == Piece.size && + cellsPieceWillFill.forall(c => c.isEmpty) - if (boardHasSpace) cellsPieceWillFill.foreach(c => c.piece = p) + if (boardHasSpace) cellsPieceWillFill.foreach(c => c.piece = p) boardHasSpace } @@ -180,10 +180,10 @@ final class Board { if (row % 2 == 1) { if (!isLast) c.next(Cell.NE) = a(i-(Board.cols-1)) - c.next(Cell.NW) = a(i-Board.cols) + c.next(Cell.NW) = a(i-Board.cols) if (row != m) { if (!isLast) c.next(Cell.SE) = a(i+(Board.cols+1)) - c.next(Cell.SW) = a(i+Board.cols) + c.next(Cell.SW) = a(i+Board.cols) } } else { if (row != 0) { @@ -212,9 +212,9 @@ final class Board { Console.print(i + "\t") for (j <- Iterator.range(0,Cell.sides)){ val c = cells(i).next(j) - if (c == null) - Console.print("-- ") - else + if (c == null) + Console.print("-- ") + else Console.printf("{0,number,00} ")(c.number) } Console.println("") @@ -241,7 +241,7 @@ final class Piece(_number: Int) { val number = _number val cells = for (i <- Array.range(0,Piece.size)) yield new PieceCell() - { + { number match { case 0 => make0 case 1 => make1 @@ -252,7 +252,7 @@ final class Piece(_number: Int) { case 6 => make6 case 7 => make7 case 8 => make8 - case 9 => make9 + case 9 => make9 } } @@ -395,12 +395,12 @@ final class Piece(_number: Int) { Console.print(i + "\t") for (j <- Iterator.range(0,Cell.sides)){ val c = cells(i).next(j) - if (c == null) - Console.print("-- ") - else + if (c == null) + Console.print("-- ") + else for (k <- Iterator.range(0,Piece.size)){ if (cells(k) == c) Console.printf(" {0,number,0} ")(k) - } + } } Console.println("") } @@ -418,13 +418,13 @@ final class Piece(_number: Int) { object Cell { val NW = 0; val NE = 1 val W = 2; val E = 3 - val SW = 4; val SE = 5 + val SW = 4; val SE = 5 val sides = 6 } abstract class Cell { - implicit def m: Manifest[T] + implicit def t: ClassTag[T] type T val next = new Array[T](Cell.sides) var marked = false @@ -437,7 +437,7 @@ abstract class Cell { final class BoardCell(_number: Int) extends { type T = BoardCell - implicit val m = manifest[BoardCell] + implicit val t = classTag[BoardCell] } with Cell { val number = _number var piece: Piece = _ @@ -448,10 +448,10 @@ final class BoardCell(_number: Int) extends { def contiguousEmptyCells(): Int = { if (!marked && isEmpty){ mark - var count = 1 + var count = 1 for (neighbour <- next) - if (neighbour != null && neighbour.isEmpty) + if (neighbour != null && neighbour.isEmpty) count = count + neighbour.contiguousEmptyCells count } else { 0 } diff --git a/test/scaladoc/resources/implicits-base-res.scala b/test/scaladoc/resources/implicits-base-res.scala index 3e3d0f01a6..65d7bdf67c 100644 --- a/test/scaladoc/resources/implicits-base-res.scala +++ b/test/scaladoc/resources/implicits-base-res.scala @@ -137,6 +137,8 @@ class ManifestA[W: Manifest](a: A[W]) { def convToManifestA(x: W): W = sys.error("dunno") } +// [Eugene to Vlad] how do I test typetags here? + /** MyTraversableOps class
* - checks if any abstract members are added - should not happen! */ @@ -144,4 +146,3 @@ trait MyTraversableOps[S] { /** The convToTraversableOps: S documentation... */ def convToTraversableOps(x: S): S } - -- cgit v1.2.3