Permalink
Browse files

Closes #3493. Review by extempore.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@22527 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
  • Loading branch information...
1 parent 502b49d commit ceb4207291ef8df06a650d504ff912ecc46cb742 prokopec committed Jul 9, 2010
Showing with 22 additions and 1 deletion.
  1. +7 −1 src/library/scala/runtime/ScalaRunTime.scala
  2. +15 −0 test/files/run/t3493.scala
@@ -235,6 +235,12 @@ object ScalaRunTime {
*
*/
def stringOf(arg: Any): String = {
+ import collection.{SortedSet, SortedMap}
+ def mapTraversable(x: Traversable[_], f: Any => String) = x match {
+ case ss: SortedSet[_] => ss.map(f)
+ case ss: SortedMap[_, _] => ss.map(f)
+ case _ => x.map(f)
+ }
def inner(arg: Any): String = arg match {
case null => "null"
// Node extends NodeSeq extends Seq[Node] strikes again
@@ -252,7 +258,7 @@ object ScalaRunTime {
// exception if you call iterator. What a world.
// And they can't be infinite either.
if (x.getClass.getName startsWith "scala.tools.nsc.io") x.toString
- else (x map inner) mkString (x.stringPrefix + "(", ", ", ")")
+ else (mapTraversable(x, inner)) mkString (x.stringPrefix + "(", ", ", ")")
case x => x toString
}
val s = inner(arg)
@@ -0,0 +1,15 @@
+
+
+
+
+object Test {
+
+ def main(args: Array[String]) {
+ import scala.collection.immutable._
+ val x = TreeSet("a", "b", "c", "d")
+ val x2 = x + "e"
+ assert(x2.toString == "TreeSet(a, b, c, d, e)")
+ assert(x2.toString == runtime.ScalaRunTime.stringOf(x2).trim)
+ }
+
+}

0 comments on commit ceb4207

Please sign in to comment.