Skip to content

Commit

Permalink
Merge pull request #112 from retronym/ticket/104
Browse files Browse the repository at this point in the history
Avoid masking real errors with NotImplemented awaiting Future[Nothing]
  • Loading branch information
retronym committed Jul 6, 2015
2 parents 7201537 + 6353443 commit 5aa390e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/scala/scala/async/internal/LiveVariables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/scala/scala/async/run/live/LiveVariablesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 5aa390e

Please sign in to comment.