aboutsummaryrefslogtreecommitdiff
path: root/src/main/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-29 19:22:00 +1000
commit6d44255964092b672accd7784ddc712d30f1d7c4 (patch)
tree32ba363fcd1416582bf1ebae01837ff4082b33d4 /src/main/scala
parentde641dc265f34b06e17dfa7c64be00219f72b670 (diff)
downloadscala-async-6d44255964092b672accd7784ddc712d30f1d7c4.tar.gz
scala-async-6d44255964092b672accd7784ddc712d30f1d7c4.tar.bz2
scala-async-6d44255964092b672accd7784ddc712d30f1d7c4.zip
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/main/scala')
-rw-r--r--src/main/scala/scala/async/internal/ExprBuilder.scala7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/main/scala/scala/async/internal/ExprBuilder.scala b/src/main/scala/scala/async/internal/ExprBuilder.scala
index f24e37e..164e85b 100644
--- a/src/main/scala/scala/async/internal/ExprBuilder.scala
+++ b/src/main/scala/scala/async/internal/ExprBuilder.scala
@@ -35,7 +35,12 @@ trait ExprBuilder {
var stats: List[Tree]
def statsAnd(trees: List[Tree]): List[Tree] = {
- val body = adaptToUnit(stats)
+ val body = stats match {
+ case init :+ last if tpeOf(last) =:= definitions.NothingTpe =>
+ adaptToUnit(init :+ Typed(last, TypeTree(definitions.AnyTpe)))
+ case _ =>
+ adaptToUnit(stats)
+ }
Try(body, Nil, adaptToUnit(trees)) :: Nil
}