diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-07-07 09:35:05 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-07-07 09:40:44 +1000 |
commit | f3f058991b207a07041672a7e119422d9054788d (patch) | |
tree | 490aec21bd028f8ff96b3b33ebcbe1ea3b76d993 /src/test/scala | |
parent | 5aa390e7cd01c7564c2c78cd786f42801a3ee1f0 (diff) | |
download | scala-async-f3f058991b207a07041672a7e119422d9054788d.tar.gz scala-async-f3f058991b207a07041672a7e119422d9054788d.tar.bz2 scala-async-f3f058991b207a07041672a7e119422d9054788d.zip |
Avoid compiler warning when awaiting Future[Unit]
During the ANF transform, we were generating a tree of the shape:
{
val temp: Unit = await(futureOfUnit)
temp
()
}
I tried to simplifiy this to avoid creating the temporary value,
but this proved difficult as it would have required changes to
the subsequent state machine transformation.
Even replacing `temp` with `()` made the state machine transform
harder.
So for now, I've just inserted `temp.asInstanceOf[Unit]` to hide
from the compiler warning.
Fixes #74
Diffstat (limited to 'src/test/scala')
-rw-r--r-- | src/test/scala/scala/async/run/WarningsSpec.scala | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/test/scala/scala/async/run/WarningsSpec.scala b/src/test/scala/scala/async/run/WarningsSpec.scala new file mode 100644 index 0000000..3a7843a --- /dev/null +++ b/src/test/scala/scala/async/run/WarningsSpec.scala @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2012-2014 Typesafe Inc. <http://www.typesafe.com> + */ + +package scala.async +package run + +import org.junit.Test + +import scala.async.internal.AsyncId +import scala.concurrent.Await +import scala.concurrent.duration._ +import scala.language.{postfixOps, reflectiveCalls} + + +class WarningsSpec { + + @Test + // https://github.com/scala/async/issues/74 + def noPureExpressionInStatementPositionWarning_t74() { + val tb = mkToolbox(s"-cp ${toolboxClasspath} -Xfatal-warnings") + // was: "a pure expression does nothing in statement position; you may be omitting necessary parentheses" + tb.eval(tb.parse { + """ + | import scala.async.internal.AsyncId._ + | async { + | if ("".isEmpty) { + | await(println("hello")) + | () + | } else 42 + | } + """.stripMargin + }) + } +} |