Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stringOf eagerly prints infinite iterable #11785

Open
som-snytt opened this issue Oct 29, 2019 · 2 comments

Comments

@som-snytt
Copy link

@som-snytt som-snytt commented Oct 29, 2019

Haven't tried dotr yet.

scala> val vs = new Iterable[Int] { def iterator = Iterator.continually(42) }
java.lang.OutOfMemoryError: Java heap space
  at java.base/java.util.Arrays.copyOf(Arrays.java:3745)
  at java.base/java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:172)
  at java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:538)
  at java.base/java.lang.StringBuilder.append(StringBuilder.java:174)
  at java.base/java.lang.StringBuilder.append(StringBuilder.java:168)
  at scala.collection.IterableOnceOps.addString(IterableOnce.scala:1170)
  at scala.collection.IterableOnceOps.addString$(IterableOnce.scala:1162)
  at $anon$1.addString(<console>:1)
  at scala.collection.IterableOnceOps.mkString(IterableOnce.scala:1112)
  at scala.collection.IterableOnceOps.mkString$(IterableOnce.scala:1110)
  at $anon$1.mkString(<console>:1)
  at scala.collection.Iterable.toString(Iterable.scala:77)
  at scala.collection.Iterable.toString$(Iterable.scala:77)
  at $anon$1.toString(<console>:1)
  at scala.runtime.ScalaRunTime$.inner$1(ScalaRunTime.scala:232)
  at scala.runtime.ScalaRunTime$.stringOf(ScalaRunTime.scala:243)
  at scala.runtime.ScalaRunTime$.replStringOf(ScalaRunTime.scala:251)
  at .$print$lzycompute(<synthetic>:8)
  ... 14 elided
@som-snytt som-snytt added the repl label Oct 29, 2019
@Jasper-M

This comment has been minimized.

Copy link
Member

@Jasper-M Jasper-M commented Oct 30, 2019

knownSize should have more possible states.

sealed trait Size
case class Known(n: Int) extends Size
case object Unknown extends Size
case object UnknownFinite extends Size
case object Infinite extends Size
@joshlemer

This comment has been minimized.

Copy link
Member

@joshlemer joshlemer commented Nov 12, 2019

Should the default Iterable#toString implementation be changed to not even force its elements? View and LazyList for instance override their toString to avoid forcing elements, maybe the forcing implementation here could be migrated to StrictOptimizedIterableOps or somewhere else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.