summaryrefslogtreecommitdiff
path: root/test/files/specialized/spec-absfun.scala
diff options
context:
space:
mode:
authorAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2011-01-17 15:18:06 +0000
committerAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2011-01-17 15:18:06 +0000
commit16e7ad360d1a902d6bd5c845642dbe14bcecdb9d (patch)
treea189e624a75dbb47a689a821208b41b0141e2ee0 /test/files/specialized/spec-absfun.scala
parentbe2778d50f1a73a941c6ffe6355f0ed401d6d8eb (diff)
downloadscala-16e7ad360d1a902d6bd5c845642dbe14bcecdb9d.tar.gz
scala-16e7ad360d1a902d6bd5c845642dbe14bcecdb9d.tar.bz2
scala-16e7ad360d1a902d6bd5c845642dbe14bcecdb9d.zip
Adapted specialization tests to track number of...
Adapted specialization tests to track number of boxings. Review by dragos
Diffstat (limited to 'test/files/specialized/spec-absfun.scala')
-rw-r--r--test/files/specialized/spec-absfun.scala44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/files/specialized/spec-absfun.scala b/test/files/specialized/spec-absfun.scala
new file mode 100644
index 0000000000..57b54235c9
--- /dev/null
+++ b/test/files/specialized/spec-absfun.scala
@@ -0,0 +1,44 @@
+
+/** Test inheritance. See #3085.
+ * Anonymous functions extend AbstractFunction1[SpecializedPair[Int], Unit]. The
+ * specialized type SpecializedPair$mcI$sp should not leak into the superclass because
+ * the definition of apply would vary covariantly, and erasure won't consider it an
+ * override of the abstract apply, leading to an AbstractMethodError at runtime.
+ */
+
+object Test {
+
+ private val Max = 1000
+
+ def main(args: Array[String]) {
+ notSpecialized()
+ specialized()
+ println(runtime.BoxesRunTime.integerBoxCount)
+ }
+
+ def notSpecialized() {
+ val pairs = for { i <- 1 to Max; j <- 1 to i } yield new Pair(i, j)
+ val time0 = System.nanoTime
+ pairs foreach { p => p.first * p.second }
+ val time1 = System.nanoTime
+// println(time1 - time0)
+ }
+
+ def specialized() {
+ val pairs = for { i <- 1 to Max; j <- 1 to i } yield new SpecializedPair(i, j)
+ val time0 = System.nanoTime
+ pairs foreach { p => p.first * p.second }
+ val time1 = System.nanoTime
+// println(time1 - time0)
+ }
+}
+
+class Pair[A](_first: A, _second: A) {
+ def first = _first
+ def second = _second
+}
+
+class SpecializedPair[@specialized(Int) A](_first: A, _second: A) {
+ def first = _first
+ def second = _second
+}