Skip to content

Commit 5aa390e

Browse files
committed
Merge pull request scala#112 from retronym/ticket/104
Avoid masking real errors with NotImplemented awaiting Future[Nothing]
2 parents 7201537 + 6353443 commit 5aa390e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/main/scala/scala/async/internal/LiveVariables.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ trait LiveVariables {
5656
// determine which fields should be live also at the end (will not be nulled out)
5757
val noNull: Set[Symbol] = liftedSyms.filter { sym =>
5858
val typeSym = tpe(sym).typeSymbol
59-
(typeSym.isClass && typeSym.asClass.isPrimitive) || liftables.exists { tree =>
59+
(typeSym.isClass && (typeSym.asClass.isPrimitive || typeSym == definitions.NothingClass)) || liftables.exists { tree =>
6060
!liftedSyms.contains(tree.symbol) && tree.exists(_.symbol == sym)
6161
}
6262
}

src/test/scala/scala/async/run/live/LiveVariablesSpec.scala

+26
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,30 @@ class LiveVariablesSpec {
263263
}
264264
baz()
265265
}
266+
267+
// https://github.com/scala/async/issues/104
268+
@Test def dontNullOutVarsOfTypeNothing_t104(): Unit = {
269+
implicit val ec: scala.concurrent.ExecutionContext = null
270+
import scala.async.Async._
271+
import scala.concurrent.duration.Duration
272+
import scala.concurrent.{Await, Future}
273+
import scala.concurrent.ExecutionContext.Implicits.global
274+
def errorGenerator(randomNum: Double) = {
275+
Future {
276+
if (randomNum < 0) {
277+
throw new IllegalStateException("Random number was too low!")
278+
} else {
279+
throw new IllegalStateException("Random number was too high!")
280+
}
281+
}
282+
}
283+
def randomTimesTwo = async {
284+
val num = _root_.scala.math.random
285+
if (num < 0 || num > 1) {
286+
await(errorGenerator(num))
287+
}
288+
num * 2
289+
}
290+
Await.result(randomTimesTwo, TestLatch.DefaultTimeout) // was: NotImplementedError
291+
}
266292
}

0 commit comments

Comments
 (0)