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
Port macros to inline meta #491
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks! Only minor comments.
import scala.annotation.compileTimeOnly | ||
import scala.meta._ | ||
|
||
@compileTimeOnly("Gets expanded away") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message appears when users forget to add the paradise compiler plugin. A clearer error might be:
"@Buildtime not expanded. Have you enabled the scala.meta paradise plugin?"
Same for GitCommit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, so that's what that annotation is for. I'll admit I didn't really understand it.
Fixed.
|
||
inline def apply(defn: Any): Any = meta { | ||
defn match { | ||
case defn @ Defn.Val(mods, pats, optType, rhs) if pats.size == 1 => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be clearer with a quasiquote, something in this direction:
case q"val $name = ???" => q"val $name = ${System.currentTimeMillis()}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally tried to wrote it with quasiquotes, but I was tripped up by the fact that you have to explicitly type the val name as ${name: Pat.Var.Term}
(otherwise it gets typed as Pat
, which you can't use when you come to construct the new tree).
Got it working the second time around. I agree that this is more readable.
dd26613
to
1acd9e6
Compare
Also changed them from defs to vals (not that it makes much difference either way)
because scalafmt does not yet support parsing of inline/meta code
1acd9e6
to
e62ce13
Compare
@olafurpg Thanks for the review. I've made some fixes and rebased. |
LGTM 👍 We're still in the very early days of scala.meta macros. In this particular case, macro annotations are a bit awkward because of the Thanks! |
macros
projectFixes #467