Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit ceb4207291ef8df06a650d504ff912ecc46cb742 1 parent 502b49d
prokopec authored
View
8 src/library/scala/runtime/ScalaRunTime.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)
View
15 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)
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.