问题
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