Skip to content

Iterator behavior different in Scala 2.13.8 and Scala 3.1.1 #12552

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

Closed
JD557 opened this issue Mar 12, 2022 · 4 comments
Closed

Iterator behavior different in Scala 2.13.8 and Scala 3.1.1 #12552

JD557 opened this issue Mar 12, 2022 · 4 comments

Comments

@JD557
Copy link

JD557 commented Mar 12, 2022

Reproduction steps

Unfortunately, I couldn't minimize this bug, but I can point to some relevant commits:

On JD557/minart@5cf7dc8, running sbt +2.13.8 imageJVM/test will fail, while sbt +3.1.1 imageJVM/test will succeed. Simply reimplementing some operations to use next/hasNext fixed the problem.

Scala version: 2.13.8 and 3.1.1 (not sure which one has the "bug")

Problem

It appears that (sometimes) on 2.13.8 calling take(n).toArray multiple times can return an empty array (similar to what happens on Vector.iterator).
OTOH, on 3.1.1, calling take(n).toArray multiple times seems to work as List.iterator, and will just keep on iterating.

I understand that "calling take(n).toArray multiple times" is undefined behavior, but since the stdlib is the same, I expected the code to have the same undefined behavior on both compiler versions

@som-snytt
Copy link

som-snytt commented Mar 12, 2022

Scala 3 uses the Scala 2 standard library but can lag, so it won't necessarily see the latest fixes.

The rule not to reuse iterators is hard and fast. Edit: I see you decided to use only next and hasNext instead of any API that requires discarding the previous iterator.

@SethTisue
Copy link
Member

SethTisue commented Mar 12, 2022

Oh good call, that does seem like a possible cause — 3.1.1 uses the 2.13.6 standard library. (The 2.13.8 upgrade has been merged but it's not clear to me yet if it will make a 3.1.x release or be held for 3.2.)

A bunch of collections changes landed in 2.13.7 (and a few more in 2.13.8).

@JD557 Can you try it with 2.13.6 and let us know?

@SethTisue
Copy link
Member

SethTisue commented Mar 12, 2022

it's not clear to me yet if it will make a 3.1.x release or be held for 3.2

duh... it'll be in 3.1.2. I should have thought to check this:

Welcome to Scala 3.1.2-RC2 (17.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                    
scala> util.Properties.versionString
val res0: String = version 2.13.8

@JD557
Copy link
Author

JD557 commented Mar 12, 2022

Indeed, 2.13.6 passes the tests.

Closing this then.
Thanks for the help, this was driving me crazy.

@JD557 JD557 closed this as completed Mar 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants