diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-07-06 15:06:49 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-07-06 15:06:49 +1000 |
commit | 6353443a0adec384172c38efac3bc96b9d2cbad2 (patch) | |
tree | 3a5944fd737d367072ae766dddaf39fcf331f50e /src | |
parent | 720153706dcb0d311f4591b30198502d9980372d (diff) | |
download | scala-async-6353443a0adec384172c38efac3bc96b9d2cbad2.tar.gz scala-async-6353443a0adec384172c38efac3bc96b9d2cbad2.tar.bz2 scala-async-6353443a0adec384172c38efac3bc96b9d2cbad2.zip |
Avoid masking real errors with NotImplemented awaiting Future[Nothing]
This commit disabled live variable analysis for intermediate values of type Nothing.
Fixes #104
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/scala/async/internal/LiveVariables.scala | 2 | ||||
-rw-r--r-- | src/test/scala/scala/async/run/live/LiveVariablesSpec.scala | 26 |
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 5b49398..db15015 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 => val typeSym = tpe(sym).typeSymbol - (typeSym.isClass && typeSym.asClass.isPrimitive) || liftables.exists { tree => + (typeSym.isClass && (typeSym.asClass.isPrimitive || typeSym == 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 30646a6..01cf911 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 + } } |