Skip to content

Commit f600550

Browse files
committed
Use non-reflective call for markForAsyncTransform
1 parent c48c0c2 commit f600550

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,16 @@ object Async {
6868
import c.universe._
6969
if (!c.compilerSettings.contains("-Xasync")) {
7070
c.abort(c.macroApplication.pos, "The async requires the compiler option -Xasync (supported only by Scala 2.12.12+ / 2.13.3+)")
71-
} else try {
71+
} else {
7272
val awaitSym = typeOf[Async.type].decl(TermName("await"))
7373
def mark(t: DefDef): Tree = {
74-
import language.reflectiveCalls
75-
c.internal.asInstanceOf[{
76-
def markForAsyncTransform(owner: Symbol, method: DefDef, awaitSymbol: Symbol, config: Map[String, AnyRef]): DefDef
77-
}].markForAsyncTransform(c.internal.enclosingOwner, t, awaitSym, Map.empty)
74+
try {
75+
c.internal.markForAsyncTransform(c.internal.enclosingOwner, t, awaitSym, Map.empty)
76+
} catch {
77+
case e: ReflectiveOperationException =>
78+
c.abort(c.macroApplication.pos, "-Xasync is provided as a Scala compiler option, but the async macro is unable to call c.internal.markForAsyncTransform. " + e.getClass.getName + " " + e.getMessage)
79+
t
80+
}
7881
}
7982
val name = TypeName("stateMachine$async")
8083
q"""
@@ -84,9 +87,6 @@ object Async {
8487
}
8588
new $name().start() : ${c.macroApplication.tpe}
8689
"""
87-
} catch {
88-
case e: ReflectiveOperationException =>
89-
c.abort(c.macroApplication.pos, "-Xasync is provided as a Scala compiler option, but the async macro is unable to call c.internal.markForAsyncTransform. " + e.getClass.getName + " " + e.getMessage)
9090
}
9191
}
9292
}

0 commit comments

Comments
 (0)