-
Notifications
You must be signed in to change notification settings - Fork 1.1k
inserting EmptyTree when recovering from StopMacroException can lead to AssertionError instead of user message #14039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Milestone
Comments
Problem is with val v = Macro[A, Request, Response]("get", uri, handler, methodName, modifiers)
entries += v |
Complete self contained example import scala.quoted.*
object Macro:
inline def apply[A, Request, Response](method: String, uri: String, handler: A, methodName: String, modifiers: Seq[RouteModifier]): Endpoint[Request, Response] =
${Macro.impl[A, Request, Response]('method, 'uri, 'handler, 'methodName, 'modifiers)}
def impl[A: Type, Request: Type, Response: Type](methodExpr: Expr[String], uriExpr: Expr[String], handlerExpr: Expr[A], methodNameExpr: Expr[String], modifiersExpr: Expr[Seq[RouteModifier]])(using Quotes): Expr[Endpoint[Request, Response]] = {
import quotes.reflect.*
report.errorAndAbort("my message")
} trait Endpoint[T, U]
type RouteModifier = String
trait Dsl[Request, Response] {
val entries = Seq.newBuilder[Endpoint[Request, Response]]
inline def get[A](inline uri: String, handler: A, methodName: String, modifiers: RouteModifier*): Unit =
entries += Macro[A, Request, Response]("get", uri, handler, methodName, modifiers)
protected inline def post[A](inline uri: String, handler: A, methodName: String, modifiers: RouteModifier*): Unit =
entries += Macro[A, Request, Response]("post", uri, handler, methodName, modifiers)
def test = get("", "", "", "")
} |
Minimized import scala.quoted.*
object Macro:
inline def apply(): Any = ${Macro.impl}
def impl(using Quotes): Expr[Any] =
quotes.reflect.report.errorAndAbort("my message") class Dsl {
val entries = Seq.newBuilder[Any]
inline def get(): Unit = entries += Macro.apply()
def test = get()
} |
Minimized witouth macros val entries = Seq.newBuilder[Any]
inline def error(): Any = compiletime.error("")
inline def get(): Unit = entries += error()
def test = get() |
nicolasstucki
added a commit
to dotty-staging/dotty
that referenced
this issue
Dec 6, 2021
This assertion can fail if the inlined function generated a error. Fixes scala#14039
olsdavis
pushed a commit
to olsdavis/dotty
that referenced
this issue
Apr 4, 2022
This assertion can fail if the inlined function generated a error. Fixes scala#14039
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From what I can see in debugger, macro throws
StopMacroException
, then Splicer catches it and insertsEmptyTree
at Splicer.scala:70. But resulting AST is incorrect and leads to further AssertionError without emitting user error.Compiler version
3.1.0
Minimized code
Output (click arrow to expand)
The text was updated successfully, but these errors were encountered: