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

View issue in M7 - NoSuchElementException thrown from iterator.toIterable.flatten (via flatMaps on views) #6271

Closed
scabug opened this issue Aug 22, 2012 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Aug 22, 2012

affects 2.10.0 M7.

Reproducable via the repl (as long as -optimise isn't on of course).

val viewed : Iterable[Iterable[Iterable[Int]]] =
List(List(List(0).view).view).view

val filtered = viewed.flatMap{ x => x.flatMap( y => List( y.filter{ _
> 0 } ) ) }

filtered.iterator.toIterable.flatten

will throw the following exception and stack trace:

NoSuchElementException("next on empty iterator") from
at scala.collection.Iterator$$anon$2.next(Iterator.scala:38)
at scala.collection.Iterator$$anon$2.next(Iterator.scala:36)
at scala.collection.Iterator$$anon$14.next(Iterator.scala:394)
at scala.collection.IterableLike$class.head(IterableLike.scala:91)
at scala.collection.SeqViewLike$AbstractTransformed.head(SeqViewLike.scala:43)
at scala.collection.immutable.Stream.scala$collection$immutable$Stream$$flatten1$1(Stream.scala:909)
at scala.collection.immutable.Stream.flatten(Stream.scala:914)
at scala.collection.immutable.Stream.flatten(Stream.scala:185)

Drop the innermost view and it won't and you'll get the
correct Stream() as the result. Using Nil.view will work, using
List(1 ...) will work, anything as long as the first predicate to
Iterator.filter works.

@scabug
Copy link
Author

scabug commented Aug 22, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6271?orig=1
Reporter: Chris (chris)
Other Milestones: 2.10.0

@scabug
Copy link
Author

scabug commented Aug 22, 2012

Chris (chris) said:
Jason investigated suggesting scala/scala@caf7eb6b is the culprit.

The code works as expected in M6 (and below to 2.8.1).

@scabug
Copy link
Author

scabug commented Sep 5, 2012

@jsuereth said:
Reduced test case:

List(0).view.flatMap(_ => List(List(1).view filter (_ < 1))).iterator.toIterable.flatten

@scabug
Copy link
Author

scabug commented Sep 5, 2012

@jsuereth said:
scala/scala#1262

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants