diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2010-02-22 13:11:49 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2010-02-22 13:11:49 +0000 |
commit | 57d38b321e73f78e03469ad5dab23e84999a817d (patch) | |
tree | eacda0bb39b039f625567edbee4cf1c6d40eeb50 /test/files/run/spec-absfun.scala | |
parent | 6e061d6f2597a3e4bdc7fcf192abbdb419917b70 (diff) | |
download | scala-57d38b321e73f78e03469ad5dab23e84999a817d.tar.gz scala-57d38b321e73f78e03469ad5dab23e84999a817d.tar.bz2 scala-57d38b321e73f78e03469ad5dab23e84999a817d.zip |
Specialized types are not substituted inside ty...
Specialized types are not substituted inside type arguments. Closes
#3085, no review.
Diffstat (limited to 'test/files/run/spec-absfun.scala')
-rw-r--r-- | test/files/run/spec-absfun.scala | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/files/run/spec-absfun.scala b/test/files/run/spec-absfun.scala new file mode 100644 index 0000000000..ab16e8febc --- /dev/null +++ b/test/files/run/spec-absfun.scala @@ -0,0 +1,43 @@ + +/** 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() + } + + 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 +} |