Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a class in Dotty with macro?

Is it possible to generate a new class with macro in Dotty, Scala 3 ?

Zlaja

like image 854
zlaja Avatar asked Dec 24 '19 21:12

zlaja


1 Answers

Currently in Dotty there is only (kind of) def macros. Currently there is no (kind of) macro annotations, which could generate a new member, new class etc.

For generation of a new member, new class etc. you can use

  • Scalameta (without or with SemanticDB, Scalafix [see also] depending on whether such generation is just syntactic or semantic), which works at the time before compile time (source generation), or

  • a compiler plugin, which works at compile time.

Let me remind you that even in Scalac the ability to generate a new member, new class etc. also appeared not from the very beginning. Such functionality (macro annotations) appeared as Macro Paradise compiler plugin to Scalac.

I can't exclude that somewhen somebody will write something like Macro Paradise for Dotty. It's too early for that, it's only feature-freeze for Dotty now, even language syntax (for example) and standard library keep changing now (there is also list of libraries that are testing their ability to work with Dotty, for example currently no Scalaz/Cats are there).

like image 69
Dmytro Mitin Avatar answered Sep 22 '22 06:09

Dmytro Mitin