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?

4

1 回答 1

4

这是否意味着宏定义需要在其自己的单独模块中才能使用?

是的。请注意,宏定义可以在同一个模块的测试中,因为它们是在主代码之后编译的。

以及如何在 build.scala 中定义它,以便宏模块在另一个之前编译?

只需添加dependsOn(<module-which-contains-macros>)<module-which-uses-them>' 的定义。

于 2015-08-15T08:02:40.100 回答