aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/scala/async/package.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2015-07-29 19:22:00 +1000
committerJason Zaugg <jzaugg@gmail.com>2015-07-30 15:51:48 +1000
commita23cfa3d3359aa5ee4e72de340344b6b1b15c3d0 (patch)
tree9f65a866e6421e119a44b196bb1da26b48c97581 /src/test/scala/scala/async/package.scala
parentdc3fd62912ef37f1f108fbf0c4ed2a5a47b7e73e (diff)
downloadscala-async-a23cfa3d3359aa5ee4e72de340344b6b1b15c3d0.tar.gz
scala-async-a23cfa3d3359aa5ee4e72de340344b6b1b15c3d0.tar.bz2
scala-async-a23cfa3d3359aa5ee4e72de340344b6b1b15c3d0.zip
[backport] Avoid dead code warnings in generated code.
If we blindly splicing `{..$stats, ..$generatedCode}`, and the last expression in `$stats` is of type `Nothing`, we'll incur a dead code warning when typechecking the block. This commit: - introduces a helper method to augment user-written stats with synthetic code - Emit a try/finally in that code (so we advance the state, even if we are about to exit the state machine in the async-block global exception handler - Hide `Nothing` typed expressions from the dead code analysis by wrapping them in an `expr: Any` Fixes #150 (the part reported in the comments, not the original ticket.)
Diffstat (limited to 'src/test/scala/scala/async/package.scala')
-rw-r--r--src/test/scala/scala/async/package.scala26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/test/scala/scala/async/package.scala b/src/test/scala/scala/async/package.scala
index 974a989..31f3d09 100644
--- a/src/test/scala/scala/async/package.scala
+++ b/src/test/scala/scala/async/package.scala
@@ -42,6 +42,32 @@ package object async {
m.mkToolBox(options = compileOptions)
}
+ import scala.tools.nsc._, reporters._
+ def mkGlobal(compileOptions: String = ""): Global = {
+ 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 settings = new Settings()
+ settings.processArgumentString(compileOptions)
+ settings.usejavacp.value = true
+ settings.embeddedDefaults(getClass.getClassLoader)
+ val reporter = new StoreReporter
+ new Global(settings, reporter)
+ }
+
def scalaBinaryVersion: String = {
val PreReleasePattern = """.*-(M|RC).*""".r
val Pattern = """(\d+\.\d+)\..*""".r