aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2015-07-27 13:15:43 +1000
committerJason Zaugg <jzaugg@gmail.com>2015-07-27 13:15:43 +1000
commit80aaf18d5111322baee73dad30eb0a81cdd62314 (patch)
tree9b2f5219aca829a2f5d756bab5e196f99b120653 /src/test
parent017928c43a6520c136d30af08d2bc3f441c2088a (diff)
downloadscala-async-80aaf18d5111322baee73dad30eb0a81cdd62314.tar.gz
scala-async-80aaf18d5111322baee73dad30eb0a81cdd62314.tar.bz2
scala-async-80aaf18d5111322baee73dad30eb0a81cdd62314.zip
Avoid masking user exception with ??? for Nothing typed expressions
Code like: val x = if (cond) throw new A else throw new B Was being transformed to: val ifRes = ??? if (cond) ifRes = throw new A else ifRes = throw new B val x = ifRes by way of the use of `gen.mkZero` which throws `???` if the requested type is `Nothing` This commit special cases `Nothing` typed expressions in a similar manner to `Unit` type expressions. The example above is now translated to: if (cond) throw new A else throw new B val x = throw new IllegalStateException() Fixes #120
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/scala/async/run/anf/AnfTransformSpec.scala42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala b/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala
index 2cce7e8..13cc351 100644
--- a/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala
+++ b/src/test/scala/scala/async/run/anf/AnfTransformSpec.scala
@@ -405,4 +405,46 @@ class AnfTransformSpec {
val applyImplicitView = tree.collect { case x if x.getClass.getName.endsWith("ApplyImplicitView") => x }
applyImplicitView.map(_.toString) mustStartWith List("view(a$macro$")
}
+
+ @Test
+ def nothingTypedIf(): Unit = {
+ import scala.async.internal.AsyncId.{async, await}
+ val result = util.Try(async {
+ if (true) {
+ val n = await(1)
+ if (n < 2) {
+ throw new RuntimeException("case a")
+ }
+ else {
+ throw new RuntimeException("case b")
+ }
+ }
+ else {
+ "case c"
+ }
+ })
+
+ assert(result.asInstanceOf[util.Failure[_]].exception.getMessage == "case a")
+ }
+
+ @Test
+ def nothingTypedMatch(): Unit = {
+ import scala.async.internal.AsyncId.{async, await}
+ val result = util.Try(async {
+ 0 match {
+ case _ if "".isEmpty =>
+ val n = await(1)
+ n match {
+ case _ if n < 2 =>
+ throw new RuntimeException("case a")
+ case _ =>
+ throw new RuntimeException("case b")
+ }
+ case _ =>
+ "case c"
+ }
+ })
+
+ assert(result.asInstanceOf[util.Failure[_]].exception.getMessage == "case a")
+ }
}