diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-07-27 13:15:43 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-07-27 14:28:39 +1000 |
commit | d74a615334de70c13bd9be00b03b4010de980b0b (patch) | |
tree | c4409678573dcc8188247df4fcac91366507c5f2 /src/test/scala/scala/async/run/anf/AnfTransformSpec.scala | |
parent | 48ede0d254ee1ea03a51c4a53fe5e8d6ae3b335d (diff) | |
download | scala-async-d74a615334de70c13bd9be00b03b4010de980b0b.tar.gz scala-async-d74a615334de70c13bd9be00b03b4010de980b0b.tar.bz2 scala-async-d74a615334de70c13bd9be00b03b4010de980b0b.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
(cherry picked from commit 80aaf18d5111322baee73dad30eb0a81cdd62314)
Diffstat (limited to 'src/test/scala/scala/async/run/anf/AnfTransformSpec.scala')
-rw-r--r-- | src/test/scala/scala/async/run/anf/AnfTransformSpec.scala | 42 |
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 757ae0b..bbc1b2b 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) mustBe List("view(a$1)") } + + @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") + } } |