scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

async + repl regression from Scala 2.12.13 #13050

Closed retronym closed 1 month ago

retronym commented 1 month ago
➜ printf 'import scala.async.Async._; import scala.concurrent._; import ExecutionContext.Implicits._; println(async { await(Future(1)) + await(Future(2)) })\n' |  scala --scala-version 2.13.12 -cp /Users/jz/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-async_2.13/1.0.1/scala-async_2.13-1.0.1.jar -Xasync
Welcome to Scala 2.13.12 (OpenJDK 64-Bit Server VM, Java 17.0.12).
Type in expressions for evaluation. Or try :help.

scala> import scala.async.Async._; import scala.concurrent._; import ExecutionContext.Implicits._; println(async { await(Future(1)) + await(Future(2)) })Future(<not completed>)
import scala.async.Async._
import scala.concurrent._
import ExecutionContext.Implicits._

scala> :quit
➜   printf 'import scala.async.Async._; import scala.concurrent._; import ExecutionContext.Implicits._; println(async { await(Future(1)) + await(Future(2)) })\n' |  scala --scala-version 2.13.13 -cp /Users/jz/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-async_2.13/1.0.1/scala-async_2.13-1.0.1.jar -Xasync
Welcome to Scala 2.13.13 (OpenJDK 64-Bit Server VM, Java 17.0.12).
Type in expressions for evaluation. Or try :help.
Oct 23, 2024 8:54:18 AM org.jline.utils.Log logr
WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)

scala> import scala.async.Async._; import scala.concurrent._; import ExecutionContext.Implicits._; println(async { await(Future(1)) + await(Future(2)) })                                                                                                                   ^
       error: `await` must be enclosed in an `async` block
                                                                                                                                      ^
       error: `await` must be enclosed in an `async` block

scala> :quit

Problem

The async phase assumes that forall subtree, tree.pos.sourcefile == unit.sourcefile.

https://github.com/scala/scala/blob/0b0fa5a60f45c8043ec8d626a37c495675c6b72f/src/compiler/scala/tools/nsc/transform/async/AsyncPhase.scala#L49

https://github.com/scala/scala/blob/0b0fa5a60f45c8043ec8d626a37c495675c6b72f/src/compiler/scala/tools/nsc/transform/async/AsyncPhase.scala#L84

This assumption doesn't hold after scala/scala#10474