aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2015-07-29 19:36:36 +1000
committerJason Zaugg <jzaugg@gmail.com>2015-07-30 15:51:50 +1000
commit3654f2225f81273f1e14d89e3def8638f99e457d (patch)
tree4e0c3fe9065ce3d8d765e18986485c2457c680b9
parenta23cfa3d3359aa5ee4e72de340344b6b1b15c3d0 (diff)
downloadscala-async-3654f2225f81273f1e14d89e3def8638f99e457d.tar.gz
scala-async-3654f2225f81273f1e14d89e3def8638f99e457d.tar.bz2
scala-async-3654f2225f81273f1e14d89e3def8638f99e457d.zip
[backport] Avoid dead code warning with async(throw T)
By declararing the parameter of `async` as by-name. Fixes #150 (the bug in the original ticket.) (cherry picked from commit 4b1dbeef9ec73612867afc5dd9c925faa8cbc30d)
-rw-r--r--src/main/scala/scala/async/Async.scala2
-rw-r--r--src/main/scala/scala/async/internal/AsyncId.scala2
-rw-r--r--src/test/scala/scala/async/run/WarningsSpec.scala19
3 files changed, 21 insertions, 2 deletions
diff --git a/src/main/scala/scala/async/Async.scala b/src/main/scala/scala/async/Async.scala
index 17a63a4..5e2d62d 100644
--- a/src/main/scala/scala/async/Async.scala
+++ b/src/main/scala/scala/async/Async.scala
@@ -42,7 +42,7 @@ object Async {
* Run the block of code `body` asynchronously. `body` may contain calls to `await` when the results of
* a `Future` are needed; this is translated into non-blocking code.
*/
- def async[T](body: T)(implicit execContext: ExecutionContext): Future[T] = macro internal.ScalaConcurrentAsync.asyncImpl[T]
+ def async[T](body: => T)(implicit execContext: ExecutionContext): Future[T] = macro internal.ScalaConcurrentAsync.asyncImpl[T]
/**
* Non-blocking await the on result of `awaitable`. This may only be used directly within an enclosing `async` block.
diff --git a/src/main/scala/scala/async/internal/AsyncId.scala b/src/main/scala/scala/async/internal/AsyncId.scala
index f9d8c0b..c92ebf4 100644
--- a/src/main/scala/scala/async/internal/AsyncId.scala
+++ b/src/main/scala/scala/async/internal/AsyncId.scala
@@ -13,7 +13,7 @@ object AsyncId extends AsyncBase {
lazy val futureSystem = IdentityFutureSystem
type FS = IdentityFutureSystem.type
- def async[T](body: T) = macro asyncIdImpl[T]
+ def async[T](body: => T) = macro asyncIdImpl[T]
def asyncIdImpl[T: c.WeakTypeTag](c: Context)(body: c.Expr[T]): c.Expr[T] = asyncImpl[T](c)(body)(c.literalUnit)
}
diff --git a/src/test/scala/scala/async/run/WarningsSpec.scala b/src/test/scala/scala/async/run/WarningsSpec.scala
index f0b414a..3b16899 100644
--- a/src/test/scala/scala/async/run/WarningsSpec.scala
+++ b/src/test/scala/scala/async/run/WarningsSpec.scala
@@ -32,6 +32,25 @@ class WarningsSpec {
}
@Test
+ // https://github.com/scala/async/issues/74
+ def noDeadCodeWarningForAsyncThrow() {
+ val global = mkGlobal("-cp ${toolboxClasspath} -Yrangepos -Ywarn-dead-code -Xfatal-warnings")
+ // was: "a pure expression does nothing in statement position; you may be omitting necessary parentheses"
+ val source =
+ """
+ | class Test {
+ | import scala.async.Async._
+ | import scala.concurrent.ExecutionContext.Implicits.global
+ | async { throw new Error() }
+ | }
+ """.stripMargin
+ val run = new global.Run
+ val sourceFile = global.newSourceFile(source)
+ run.compileSources(sourceFile :: Nil)
+ assert(!global.reporter.hasErrors, global.reporter.asInstanceOf[StoreReporter].infos)
+ }
+
+ @Test
def noDeadCodeWarning() {
val global = mkGlobal("-cp ${toolboxClasspath} -Yrangepos -Ywarn-dead-code -Xfatal-warnings")
val source = """