8000 Make async blackbox / throw a meaningful exception from await · scala/scala-async@a2e32d8 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a2e32d8

Browse files
committed
Make async blackbox / throw a meaningful exception from await
1 parent b8cf254 commit a2e32d8

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/main/scala/scala/async/Async.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package scala.async
1515
import scala.language.experimental.macros
1616
import scala.concurrent.{ExecutionContext, Future}
1717
import scala.annotation.compileTimeOnly
18-
import scala.reflect.macros.whitebox
18+
import scala.reflect.macros.blackbox
1919

2020
/**
2121
* Async blocks provide a direct means to work with [[scala.concurrent.Future]].
@@ -60,11 +60,9 @@ object Async {
6060
* in the `onComplete` handler of `awaitable`, and will *not* block a thread.
6161
*/
6262
@compileTimeOnly("[async] `await` must be enclosed in an `async` block")
63-
def await[T](awaitable: Future[T]): T = ??? // No implementation here, as calls to this are translated to `onComplete` by the macro.
63+
def await[T](awaitable: Future[T]): T = throw new UnsupportedOperationException("Calls to Async.await should have been treated as compiler intrinsics and rewritten!")
6464

65-
def asyncImpl[T: c.WeakTypeTag](c: whitebox.Context)
66-
(body: c.Tree)
67-
(execContext: c.Tree): c.Tree = {
65+
def asyncImpl[T: c.WeakTypeTag](c: blackbox.Context)(body: c.Tree)(execContext: c.Tree): c.Tree = {
6866
import c.universe._
6967
if (!c.compilerSettings.contains("-Xasync")) {
7068
c.abort(c.macroApplication.pos, "The async requires the compiler option -Xasync (supported only by Scala 2.12.12+ / 2.13.3+)")

src/test/scala/scala/async/FutureSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class FutureSpec {
102102
val a = await(future0.mapTo[Int])
103103
val b = await((Future { (a * 2).toString }).mapTo[Int])
104104
val c = await(Future { (7 * 2).toString })
105-
b + "-" + c
105+
b.toString + "-" + c
106106
}
107107

108108
Await.result(future1, defaultTimeout) mustBe ("10-14")
@@ -129,7 +129,7 @@ class FutureSpec {
129129
Res(a: Int) <- asyncReq(Req("Hello"))
130130
Res(b: Int) <- asyncReq(Req(a))
131131
Res(c: Int) <- asyncReq(Req(7))
132-
} yield b + "-" + c
132+
} yield b.toString + "-" + c
133133

134134
Await.result(future1, defaultTimeout) mustBe ("10-14")
135135
intercept[NoSuchElementException] { Await.result(future2, defaultTimeout) }

src/test/scala/scala/async/TestUtil.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ object TestUtil {
5959
}
6060

6161
implicit class objectops(obj: Any) {
62-
def mustBe(other: Any): Unit = assert(obj == other, obj + " is not " + other)
62+
def mustBe(other: Any): Unit = assert(obj == other, obj.toString + " is not " + other)
6363

6464
def mustEqual(other: Any): Unit = mustBe(other)
6565
}

0 commit comments

Comments
 (0)
0