Search code examples
scalascala-macrosscala-3scala-macro-paradise

Macro Annotations in Scala 3


The following is a quote from Macros: the Plan for Scala 3 from more than 3 years ago:

For instance, one will be able to define a macro annotation @json that adds a JSON serializer to a type.

Any idea how/if this is actually possible in Scala 3?

More generally, is there anything in Scala 3 that can provide "Macro Annotations" functionality? The following is a quote from Macro Annotations - Scala 2.13:

Unlike in the previous versions of macro paradise, macro annotations in 2.0 are done right in the sense that they: 1) apply not just to classes and objects, but to arbitrary definitions, 2) allow expansions of classes to modify or even create companion objects


Solution

  • As of June 2021, macro annotations are not supported in Scala 3, and they are not mentioned anywhere in the doc.

    Right now, if you'd like to generate methods, classes or objects, I believe you have to use scalameta or write a compiler plugin.

    Obviously, this situation might change in the future, macro annotations were not part of Scala 2 at the beginning either.