File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed
test/scala/scala/async/run Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ object Async {
4242 * Run the block of code `body` asynchronously. `body` may contain calls to `await` when the results of
4343 * a `Future` are needed; this is translated into non-blocking code.
4444 */
45- def async [T ](body : T )(implicit execContext : ExecutionContext ): Future [T ] = macro internal.ScalaConcurrentAsync .asyncImpl[T ]
45+ def async [T ](body : => T )(implicit execContext : ExecutionContext ): Future [T ] = macro internal.ScalaConcurrentAsync .asyncImpl[T ]
4646
4747 /**
4848 * Non-blocking await the on result of `awaitable`. This may only be used directly within an enclosing `async` block.
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ object AsyncId extends AsyncBase {
1313 lazy val futureSystem = IdentityFutureSystem
1414 type FS = IdentityFutureSystem .type
1515
16- def async [T ](body : T ) = macro asyncIdImpl[T ]
16+ def async [T ](body : => T ) = macro asyncIdImpl[T ]
1717
1818 def asyncIdImpl [T : c.WeakTypeTag ](c : Context )(body : c.Expr [T ]): c.Expr [T ] = asyncImpl[T ](c)(body)(c.literalUnit)
1919}
Original file line number Diff line number Diff line change @@ -31,6 +31,25 @@ class WarningsSpec {
3131 })
3232 }
3333
34+ @ Test
35+ // https://github.com/scala/async/issues/74
36+ def noDeadCodeWarningForAsyncThrow () {
37+ val global = mkGlobal(" -cp ${toolboxClasspath} -Yrangepos -Ywarn-dead-code -Xfatal-warnings" )
38+ // was: "a pure expression does nothing in statement position; you may be omitting necessary parentheses"
39+ val source =
40+ """
41+ | class Test {
42+ | import scala.async.Async._
43+ | import scala.concurrent.ExecutionContext.Implicits.global
44+ | async { throw new Error() }
45+ | }
46+ """ .stripMargin
47+ val run = new global.Run
48+ val sourceFile = global.newSourceFile(source)
49+ run.compileSources(sourceFile :: Nil )
50+ assert(! global.reporter.hasErrors, global.reporter.asInstanceOf [StoreReporter ].infos)
51+ }
52+
3453 @ Test
3554 def noDeadCodeWarning () {
3655 val global = mkGlobal(" -cp ${toolboxClasspath} -Yrangepos -Ywarn-dead-code -Xfatal-warnings" )
You can’t perform that action at this time.
0 commit comments