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 {
42
42
* Run the block of code `body` asynchronously. `body` may contain calls to `await` when the results of
43
43
* a `Future` are needed; this is translated into non-blocking code.
44
44
*/
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 ]
46
46
47
47
/**
48
48
* 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 {
13
13
lazy val futureSystem = IdentityFutureSystem
14
14
type FS = IdentityFutureSystem .type
15
15
16
- def async [T ](body : T ) = macro asyncIdImpl[T ]
16
+ def async [T ](body : => T ) = macro asyncIdImpl[T ]
17
17
18
18
def asyncIdImpl [T : c.WeakTypeTag ](c : Context )(body : c.Expr [T ]): c.Expr [T ] = asyncImpl[T ](c)(body)(c.literalUnit)
19
19
}
Original file line number Diff line number Diff line change @@ -31,6 +31,25 @@ class WarningsSpec {
31
31
})
32
32
}
33
33
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
+
34
53
@ Test
35
54
def noDeadCodeWarning () {
36
55
val global = mkGlobal(" -cp ${toolboxClasspath} -Yrangepos -Ywarn-dead-code -Xfatal-warnings" )
You can’t perform that action at this time.
0 commit comments