What does it mean when macro annotation cannot be used in the same compilation that defines it?

你离开我真会死。 提交于 2019-12-23 12:38:19

问题


I am curious about this statement:

Error:(3, 18) ...another possibility is that you try to use macro annotation in the same compilation run that defines it)

I tried googling and found this:

Finally, remember that using macros requires compilation to happen in two steps: first, compile the macros, then compile the code where the macros are used. This is necessary so that your macros can be run before the rest of your code is compiled. For example if you use SBT, you can configure Build.scala to use two modules, a “macros” module containing your macros, and a “root” module that depends on the “macros” module.

Does this mean that the macro definitions need to be in its own separate module to be used? And how do I define it in the build.scala so that the macro module compiles before the other?


回答1:


Does this mean that the macro definitions need to be in its own separate module to be used?

Yes. Note that macro definitions can be in the same module's tests because they are compiled after the main code.

And how do I define it in the build.scala so that the macro module compiles before the other?

Just add dependsOn(<module-which-contains-macros>) to <module-which-uses-them>'s definition.



来源:https://stackoverflow.com/questions/32021707/what-does-it-mean-when-macro-annotation-cannot-be-used-in-the-same-compilation-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!