From 4b1dbeef9ec73612867afc5dd9c925faa8cbc30d Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 29 Jul 2015 19:36:36 +1000 Subject: 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.) --- src/test/scala/scala/async/run/WarningsSpec.scala | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/test') 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 @@ -31,6 +31,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") -- cgit v1.2.3