Skip to content

Commit

Permalink
Closes #3493. Review by extempore.
Browse files Browse the repository at this point in the history
git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@22527 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
  • Loading branch information
prokopec committed Jul 9, 2010
1 parent 502b49d commit ceb4207
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/library/scala/runtime/ScalaRunTime.scala
Expand Up @@ -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
Expand All @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions test/files/run/t3493.scala
@@ -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.