我不确定为什么这个简单的代码会导致错误:
object Main {
def main(args: Array[String]) {
val userInterrupted: Future[String] = async {
var inp = await { Future.userInput("")}
"You entered... " + inp
}
}
}
错误消息:
[error] /Users/reactive programming coursera/nodescala/src/main/scala/nodescala/Main.scala:18: macro has not been expanded
[error] val userInterrupted: Future[String] = async {
[error] ^
[error] one error found
[error] (assignment/compile:compile) Compilation failed
答案 0 :(得分:10)
这似乎是known problem(已修复但可能在Scala 2.11之前无法使用)。由于它与隐式有关,您可以尝试通过隐式显式来解决它:
var inp = await { FutureCompanionOps(Future).userInput("") }
(由于这个问题与Coursera assignment有关,我知道你已经定义了一个implicit class FutureCompanionOps[T]
,它带有一个类型参数,这似乎是问题所在。)