aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2015-07-06 15:06:49 +1000
committerJason Zaugg <jzaugg@gmail.com>2015-07-06 15:11:08 +1000
commitf1d9667189ebad285553e912a2eac4a64093c8bf (patch)
tree4522b6199fc4316e4c15522733662dc590f3679e
parent93dab7a6fe81227953d087813d5cab0d0634b9f2 (diff)
downloadscala-async-f1d9667189ebad285553e912a2eac4a64093c8bf.tar.gz
scala-async-f1d9667189ebad285553e912a2eac4a64093c8bf.tar.bz2
scala-async-f1d9667189ebad285553e912a2eac4a64093c8bf.zip
[backport] Avoid masking real errors with NotImplemented awaiting Future[Nothing]
This commit disabled live variable analysis for intermediate values of type Nothing. Fixes #104 (cherry picked from commit 6353443a0adec384172c38efac3bc96b9d2cbad2)
-rw-r--r--src/main/scala/scala/async/internal/LiveVariables.scala2
-rw-r--r--src/test/scala/scala/async/run/live/LiveVariablesSpec.scala26
2 files changed, 27 insertions, 1 deletions
diff --git a/src/main/scala/scala/async/internal/LiveVariables.scala b/src/main/scala/scala/async/internal/LiveVariables.scala
index 23063ba..79ba18e 100644
--- a/src/main/scala/scala/async/internal/LiveVariables.scala
+++ b/src/main/scala/scala/async/internal/LiveVariables.scala
@@ -56,7 +56,7 @@ trait LiveVariables {
// determine which fields should be live also at the end (will not be nulled out)
val noNull: Set[Symbol] = liftedSyms.filter { sym =>
- sym.tpe.typeSymbol.isPrimitiveValueClass || liftables.exists { tree =>
+ sym.tpe.typeSymbol.isPrimitiveValueClass || sym.tpe.typeSymbol == definitions.NothingClass || liftables.exists { tree =>
!liftedSyms.contains(tree.symbol) && tree.exists(_.symbol == sym)
}
}
diff --git a/src/test/scala/scala/async/run/live/LiveVariablesSpec.scala b/src/test/scala/scala/async/run/live/LiveVariablesSpec.scala
index 17d33af..09d01c1 100644
--- a/src/test/scala/scala/async/run/live/LiveVariablesSpec.scala
+++ b/src/test/scala/scala/async/run/live/LiveVariablesSpec.scala
@@ -263,4 +263,30 @@ class LiveVariablesSpec {
}
baz()
}
+
+ // https://github.com/scala/async/issues/104
+ @Test def dontNullOutVarsOfTypeNothing_t104(): Unit = {
+ implicit val ec: scala.concurrent.ExecutionContext = null
+ import scala.async.Async._
+ import scala.concurrent.duration.Duration
+ import scala.concurrent.{Await, Future}
+ import scala.concurrent.ExecutionContext.Implicits.global
+ def errorGenerator(randomNum: Double) = {
+ Future {
+ if (randomNum < 0) {
+ throw new IllegalStateException("Random number was too low!")
+ } else {
+ throw new IllegalStateException("Random number was too high!")
+ }
+ }
+ }
+ def randomTimesTwo = async {
+ val num = _root_.scala.math.random
+ if (num < 0 || num > 1) {
+ await(errorGenerator(num))
+ }
+ num * 2
+ }
+ Await.result(randomTimesTwo, TestLatch.DefaultTimeout) // was: NotImplementedError
+ }
}