diff --git a/src/main/scala/scala/async/internal/LiveVariables.scala b/src/main/scala/scala/async/internal/LiveVariables.scala index 5b493984..db150150 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 30646a67..01cf9111 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 + } }