为什么以下在 Scala REPL 中抛出异常?

Why does following throw exception in Scala REPL?

为什么以下代码的最后一行在 scala REPL 中抛出错误?

import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global

// This is okay
val futureInt = Future[Int] { 42 }
val v1 = Await.result(futureInt, 1.second)

// This throw error: java.lang.NoClassDefFoundError: Could not initialize class $line8.$read$$iw$$iw$$iw$$iw$$iw$$iw$
val v2 = Await.result(Future[Int]{ 42 }, 1.second)

但是当我创建一个 main class 并执行相同的代码时它工作正常:

import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global

object Main {
  def main(args: Array[String]): Unit = {
    val futureInt = Future[Int] { 42 }
    val v1 = Await.result(futureInt, 1.second)
    val v2 = Await.result(Future[Int] { 44 }, 1.second)
    println(s"v1=$v1, v2=$v2 ")
  }
}

Output:

v1=42, v2=44

此错误(包括您的确切来源)正在针对 scala 的此错误中进行跟踪:

https://github.com/scala/bug/issues/9076#issuecomment-292435527