diff options
author | Antonio Cunei <antonio.cunei@epfl.ch> | 2010-06-16 19:45:38 +0000 |
---|---|---|
committer | Antonio Cunei <antonio.cunei@epfl.ch> | 2010-06-16 19:45:38 +0000 |
commit | f553dd89103385913dc2668ccdd1c013ca3c299f (patch) | |
tree | a502954a8450911ec131dccf8ed3073fe6bb185c | |
parent | a99d8f02f69610f37e8de0336270cfc61eb2ad1e (diff) | |
download | scala-f553dd89103385913dc2668ccdd1c013ca3c299f.tar.gz scala-f553dd89103385913dc2668ccdd1c013ca3c299f.tar.bz2 scala-f553dd89103385913dc2668ccdd1c013ca3c299f.zip |
Merged revisions 22321 via svnmerge from
https://lampsvn.epfl.ch/svn-repos/scala/scala/trunk
........
r22321 | prokopec | 2010-06-16 18:40:02 +0200 (Wed, 16 Jun 2010) | 1 line
Fixes #3563. Review by extempore.
........
-rw-r--r-- | src/library/scala/collection/IterableLike.scala | 7 | ||||
-rw-r--r-- | src/library/scala/collection/TraversableOnce.scala | 10 | ||||
-rw-r--r-- | test/files/run/bug3563.scala | 21 |
3 files changed, 35 insertions, 3 deletions
diff --git a/src/library/scala/collection/IterableLike.scala b/src/library/scala/collection/IterableLike.scala index ca149809b3..da18c712f5 100644 --- a/src/library/scala/collection/IterableLike.scala +++ b/src/library/scala/collection/IterableLike.scala @@ -352,6 +352,13 @@ self => override /*TraversableLike*/ def toStream: Stream[A] = iterator.toStream + /** Converts this $coll to a sequence. + * + * $willNotTerminateInf + * @return a sequence containing all the elements of this $coll. + */ + override /*TraversableOnce*/ def toSeq: Seq[A] = toList + /** Method called from equality methods, so that user-defined subclasses can * refuse to be equal to other collections of the same kind. * @param that The object with which this $coll should be compared diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala index 5d09b6d2c6..b6c0ce146e 100644 --- a/src/library/scala/collection/TraversableOnce.scala +++ b/src/library/scala/collection/TraversableOnce.scala @@ -399,15 +399,19 @@ trait TraversableOnce[+A] { def toList: List[A] = new ListBuffer[A] ++= self toList /** Converts this $coll to an iterable collection. Note that - * the choice of target Iterable must be lazy as this TraversableOnce - * may be lazy and unevaluated. + * the choice of target `Iterable` is lazy in this default implementation + * as this `TraversableOnce` may be lazy and unevaluated (i.e. it may + * be an iterator which is only traversable once). * * $willNotTerminateInf * @return an `Iterable` containing all elements of this $coll. */ def toIterable: Iterable[A] = toStream - /** Converts this $coll to a sequence. As with toIterable, it must be lazy. + /** Converts this $coll to a sequence. As with `toIterable`, it's lazy + * in this default implementation, as this `TraversableOnce` may be + * lazy and unevaluated. + * * $willNotTerminateInf * @return a sequence containing all elements of this $coll. */ diff --git a/test/files/run/bug3563.scala b/test/files/run/bug3563.scala new file mode 100644 index 0000000000..8abbb60803 --- /dev/null +++ b/test/files/run/bug3563.scala @@ -0,0 +1,21 @@ + + + + + +// ticket #3563 +object Test { + + def main(args: Array[String]) { + var sum = 0 + val setseq = Set(1, 2, 3, 4).toSeq + setseq.map( n => { sum += n; n * n }).head + assert(sum == 10) + + sum = 0 + val mapseq = Map(1 -> 1, 2 -> 2, 3 -> 3, 4 -> 4).toSeq + mapseq.map( n => { sum += n._1; (n._1 + n._1, n._2 * n._2) }).head + assert(sum == 10) + } + +} |