aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/scala/async/run/WarningsSpec.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/scala/scala/async/run/WarningsSpec.scala')
-rw-r--r--src/test/scala/scala/async/run/WarningsSpec.scala48
1 files changed, 45 insertions, 3 deletions
diff --git a/src/test/scala/scala/async/run/WarningsSpec.scala b/src/test/scala/scala/async/run/WarningsSpec.scala
index 3a7843a..00c6466 100644
--- a/src/test/scala/scala/async/run/WarningsSpec.scala
+++ b/src/test/scala/scala/async/run/WarningsSpec.scala
@@ -7,10 +7,8 @@ package run
import org.junit.Test
-import scala.async.internal.AsyncId
-import scala.concurrent.Await
-import scala.concurrent.duration._
import scala.language.{postfixOps, reflectiveCalls}
+import scala.tools.nsc.reporters.StoreReporter
class WarningsSpec {
@@ -32,4 +30,48 @@ class WarningsSpec {
""".stripMargin
})
}
+
+ @Test
+ // https://github.com/scala/async/issues/74
+ def noDeadCodeWarningForAsyncThrow() {
+ val global = mkGlobal("-cp ${toolboxClasspath} -Yrangepos -Ywarn-dead-code -Xfatal-warnings -Ystop-after:refchecks")
+ // 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 noDeadCodeWarningInMacroExpansion() {
+ val global = mkGlobal("-cp ${toolboxClasspath} -Yrangepos -Ywarn-dead-code -Xfatal-warnings -Ystop-after:refchecks")
+ val source = """
+ | class Test {
+ | def test = {
+ | import scala.async.Async._, scala.concurrent._, ExecutionContext.Implicits.global
+ | async {
+ | val opt = await(async(Option.empty[String => Future[Unit]]))
+ | opt match {
+ | case None =>
+ | throw new RuntimeException("case a")
+ | case Some(f) =>
+ | await(f("case b"))
+ | }
+ | }
+ | }
+ |}
+ """.stripMargin
+ val run = new global.Run
+ val sourceFile = global.newSourceFile(source)
+ run.compileSources(sourceFile :: Nil)
+ assert(!global.reporter.hasErrors, global.reporter.asInstanceOf[StoreReporter].infos)
+ }
}