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

LinearSeq extension problem solved #7443

Merged
merged 1 commit into from
Nov 21, 2018
Merged

Conversation

vincentdehaan
Copy link
Contributor

When extending a LinearSeq, calling iterator resulted in an
infinite loop causing a StackOverflowError.

Fixes scala/bug#11262

@scala-jenkins scala-jenkins added this to the 2.13.0-RC1 milestone Nov 17, 2018
@vincentdehaan
Copy link
Contributor Author

I just signed the CLA.

@NthPortal NthPortal added the library:collections PRs involving changes to the standard collection library label Nov 17, 2018
Copy link
Contributor

@NthPortal NthPortal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this does fix the problem here, the underlying issue I believe is that toSeq is broken for LinearSeq (it should just return this or coll or something). I think it would be better to fix toSeq instead.

src/library/scala/collection/LinearSeq.scala Show resolved Hide resolved
@vincentdehaan
Copy link
Contributor Author

The problem was indeed that toSeq was broken for LinearSeq. This was caused by an infinite loop of which both toSeq and iterator (and a handful of other methods, as shown by the stack trace) are part. This seemed to be the most elegant way to fix it, and toSeq has been fixed as well.

When extending a LinearSeq, calling iterator resulted in an
infinite loop causing a StackOverflowError.

Fixes scala/bug#11262
@julienrf
Copy link
Contributor

Indeed, toSeq should return this, what’s the current behaviour?

@NthPortal
Copy link
Contributor

@julienrf immutable.Seq.from(this), inherited from IterableOnceOps

@julienrf
Copy link
Contributor

Actually, this is normal, only the immutable.Seq can implement toSeq by returning this. The default behaviour is to build a List from the receiver’s iterator. However, the current implementation of iterator in LinearSeq calls toSeq, hence the infinite loop. So, this PR contains the correct fix.

@lrytz lrytz merged commit 1a3165b into scala:2.13.x Nov 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
library:collections PRs involving changes to the standard collection library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants