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

1

4

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?

Pineal answered 15/8, 2015 at 5:2 Comment(0)
F
4

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.

Flatt answered 15/8, 2015 at 8:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.