From 6d44255964092b672accd7784ddc712d30f1d7c4 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 29 Jul 2015 19:22:00 +1000 Subject: 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.) --- src/test/scala/scala/async/package.scala | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/test/scala/scala/async/package.scala') diff --git a/src/test/scala/scala/async/package.scala b/src/test/scala/scala/async/package.scala index 166edaa..8f23a8c 100644 --- a/src/test/scala/scala/async/package.scala +++ b/src/test/scala/scala/async/package.scala @@ -51,6 +51,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 -- cgit v1.2.3 From 7238bc1982cb1d87157c650115a2ae92a58430c9 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Thu, 30 Jul 2015 14:45:37 +1000 Subject: Make nsc.Global based tests work under SBT And remove unused code. --- src/test/scala/scala/async/package.scala | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'src/test/scala/scala/async/package.scala') diff --git a/src/test/scala/scala/async/package.scala b/src/test/scala/scala/async/package.scala index 8f23a8c..9fbb7df 100644 --- a/src/test/scala/scala/async/package.scala +++ b/src/test/scala/scala/async/package.scala @@ -53,26 +53,12 @@ package object async { 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 + val initClassPath = settings.classpath.value settings.embeddedDefaults(getClass.getClassLoader) + if (initClassPath == settings.classpath.value) + settings.usejavacp.value = true // not running under SBT, try to use the Java claspath instead val reporter = new StoreReporter new Global(settings, reporter) } -- cgit v1.2.3