Skip to content
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

Can't use a macro annotation class as a normal type in the compilation unit it's defined in #79

Open
alexeyr opened this issue Jun 20, 2016 · 3 comments

Comments

@alexeyr
Copy link

alexeyr commented Jun 20, 2016

I have a macro annotation with parameters: class AnnotationType(...) extends StaticAnnotation. Since c.prefix.tree in the macro implementation is the tree for the annotation constructor, I've tried
c.eval(c.Expr[AnnotationType](c.prefix.tree)) and c.eval(c.prefix.asInstanceOf[c.Expr[AnnotationType]].
The compiler complains that it can't expand AnnotationType even though it isn't used as an annotation and shouldn't be expanded. If this worked, it would simplify http://stackoverflow.com/questions/32631372/getting-parameters-from-scala-macro-annotation and http://stackoverflow.com/questions/37891855/macro-annotation-with-default-arguments.

@xeno-by
Copy link
Member

xeno-by commented Jun 20, 2016

This is a limitation of how macro annotation expansion is implemented for scalac.

I'd like to detect situations when a user forgot to enable the macro paradise plugin and, as a result, their annotations have spuriously failed to expand. There's the @compileTimeOnly annotation that can be used for this, but unfortunately it not only produces errors on usages of macro annotations in annotation positions, but also on any kind of usages.

A better mechanism to address the original issue may enable us to be more permissive wrt other kinds of usages of macro annotations.

@alexeyr
Copy link
Author

alexeyr commented Jun 21, 2016

Unfortunately, it doesn't work without @compileTimeOnly either.

@xeno-by
Copy link
Member

xeno-by commented Jun 21, 2016

That's because the paradise plugin automatically adds the @compileTimeOnly annotation to macro annotations.

SethTisue pushed a commit to scalacommunitybuild/paradise that referenced this issue Nov 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants