summaryrefslogtreecommitdiff
path: root/test/files/run/bug3984.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-01-09 06:30:35 +0000
committerPaul Phillips <paulp@improving.org>2011-01-09 06:30:35 +0000
commitc8ddf01621417ef1e5f07682a360ff1b1ebfd416 (patch)
treedd963aef7dbf31bfc5832f8a7f96a0c02edc63f1 /test/files/run/bug3984.scala
parent7d9fb75275430bcdecf8541d0d30c59a7e10881a (diff)
downloadscala-c8ddf01621417ef1e5f07682a360ff1b1ebfd416.tar.gz
scala-c8ddf01621417ef1e5f07682a360ff1b1ebfd416.tar.bz2
scala-c8ddf01621417ef1e5f07682a360ff1b1ebfd416.zip
Closes #3984 by the most arduous and indirect r...
Closes #3984 by the most arduous and indirect route imaginable: abstracts the common code out of the TrieIterators in HashMap and HashSet. When I raised this flag to find out if anyone would open fire, all was quiet on the western front. Although I wouldn't want to write code like this as an everyday thing, I think it serves as a nice showcase for some of the abstraction challenges we're up against: performance looks the same and I will never again have to fix the same bug in two places. Review by rompf.
Diffstat (limited to 'test/files/run/bug3984.scala')
-rw-r--r--test/files/run/bug3984.scala35
1 files changed, 33 insertions, 2 deletions
diff --git a/test/files/run/bug3984.scala b/test/files/run/bug3984.scala
index 3e4d2edf53..0747b0ee25 100644
--- a/test/files/run/bug3984.scala
+++ b/test/files/run/bug3984.scala
@@ -1,4 +1,4 @@
-object Test {
+object SetBug {
import scala.collection.immutable.{ Set => ImmutSet }
import scala.collection.mutable.{ Set => MutSet }
@@ -6,16 +6,47 @@ object Test {
override def hashCode: Int = h
}
- def main (args: Array[String]) {
+ def run() {
var is = ImmutSet.empty[IH]
var ms = MutSet.empty[IH]
for (ih <- List(IH(2,0),IH(0,0),IH(4,4),IH(6,4),IH(-8,1520786080))) {
is = is + ih
ms = ms + ih
}
+ assert(is == ms)
val x = IH(6,4)
is = is - x
ms = ms - x
assert(is == ms)
}
}
+
+object MapBug {
+ import scala.collection.immutable.{ Map => ImmutMap }
+ import scala.collection.mutable.{ Map => MutMap }
+
+ case class IH (i: Int, h: Int) {
+ override def hashCode: Int = h
+ }
+
+ def run() {
+ var im = ImmutMap.empty[IH,IH]
+ var mm = MutMap.empty[IH,IH]
+ for (ih <- List(IH(2,0),IH(0,0),IH(4,4),IH(6,4),IH(-8,1520786080))) {
+ im = im + ((ih,ih))
+ mm = mm + ((ih,ih))
+ }
+ assert(im == mm)
+ val x = IH(6,4)
+ im = im - x
+ mm = mm - x
+ assert(im == mm)
+ }
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ SetBug.run()
+ MapBug.run()
+ }
+}