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

Bug in Iterator.span #9913

Closed
scabug opened this issue Sep 5, 2016 · 3 comments
Closed

Bug in Iterator.span #9913

scabug opened this issue Sep 5, 2016 · 3 comments

Comments

@scabug
Copy link

scabug commented Sep 5, 2016

example code

object SpanBug extends App {
  def test(thunk: => Boolean, m: String): Unit = if(!thunk) throw new RuntimeException(m)

  val (tLeft, tRight) = Iterator(1,2,3).span(_ => true)
  test(tRight.hasNext == false, "tRight.hasNext shouldBe false")
  test(tLeft.hasNext == true, "tLeft.hasNext shouldBe true")
}

this problem is not occurred in scala 2.11.7.
when call tRight.hasNext before tLeft.hasNext, tLeft.hasNext returns unexpected value.

steps to reproduce:

@scabug
Copy link
Author

scabug commented Sep 5, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9913?orig=1
Reporter: seraph (seraphr)
Affected Versions: 2.11.8, 2.12.0-M5

@scabug
Copy link
Author

scabug commented Sep 6, 2016

@som-snytt said (edited on Sep 6, 2016 5:25:59 AM UTC):

$ scala
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
Type in expressions for evaluation. Or try :help.

scala> { val (l,r) = Iterator(1,2,3).span(_ => true) ; l.hasNext && !r.hasNext }
res0: Boolean = true

scala> { val (l,r) = Iterator(1,2,3).span(_ => true) ; !r.hasNext && l.hasNext }
res1: Boolean = false

scala> val (l,r) = Iterator(1,2,3).span(_ => true)
l: Iterator[Int] = non-empty iterator
r: Iterator[Int] = unknown-if-empty iterator

scala> !r.hasNext && l.hasNext
res2: Boolean = true

scala> { val (l,r) = Iterator(1,2,3).span(_ => true) ; l.hasNext ; assert(!r.hasNext) ; l.toList }
res3: List[Int] = List(1)

@scabug
Copy link
Author

scabug commented Sep 6, 2016

@som-snytt said:
scala/scala#5378

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

2 participants