Skip to content

Loop doesn't terminate when compiled by dotty #7843

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
laurynaslubys opened this issue Dec 23, 2019 · 0 comments
Closed

Loop doesn't terminate when compiled by dotty #7843

laurynaslubys opened this issue Dec 23, 2019 · 0 comments

Comments

@laurynaslubys
Copy link

minimized code

object Main {

  val thunkFuture: Future[() => String] = Future.successful(() => throw new RuntimeException("Whoops"))

  final def shouldTerminate: Future[Unit] =
    thunkFuture.flatMap { thunk =>
      def fold() = {
        var done = false
        while (!done) {
          println(s"done outside try: $done")
          try {
            thunk()
          } catch {
            case _: Throwable =>
              println("setting done to true")
              done = true
              println(s"done in catch clause: $done")
          }
        }
      }

      Future {
        fold()
      }
    }


  def main(args: Array[String]): Unit = {
    Await.result(shouldTerminate, Duration.Inf)
    println("done")
  }
}

The program doesn't terminate in 0.21.0-RC1, but terminates correctly in scala 2.12

expectation

terminates and produces output:

[info] done outside try: false
[info] setting done to true
[info] done in catch clause: true
[info] done

actual

doesn't terminate and produces output:

[info] done outside try: false
[info] setting done to true
[info] done in catch clause: true
[info] done outside try: false
[info] setting done to true
[info] done in catch clause: true
... repeated
odersky added a commit that referenced this issue Dec 25, 2019
Fix #7843: Move LiftTry back to before CapturedVars
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

1 participant