Search code examples
scalacode-generationscala-macrosscala-macro-paradise

Can I run a Scala macro automatically when I extend a given type?


Currently, I use a Scala macro annotation to automatically generate some code into a Scala object. It works like this:

@constants
object PopoverCommands extends Constants { … }

I find it somewhat redundant to have to extend Constants and to annotate PopoverCommands with @constants. I know the macro annotation can insert the extends Constants part. My question goes the other way round: is there any way I can run some macro code (e.g. simulate the presence of @constants) by simply extending a type (here, Constants)?


Solution

  • No, this isn't currently possible.