I have the following code:
object Macros { import scala.language.experimental.macros import scala.reflect.macros.blackbox def hello(): Unit = macro hello_impl def hello_impl(c: blackbox.Context)(): c.Expr[Unit] = { import c.universe._ reify { println("Hello World!") } } } object Main { def main(args: Array[String]): Unit = { Macros.hello() } }
It throws the following compilation error:
Error:(21, 17) macro implementation not found: hello (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them) Macros.hello() ^
My question is: is there a way to βtrickβ the compiler into using macro extensions in the same file that they are defined? My motivation is this: I like the code in Scala, and lately I asked some problems in the online judge Codeforces and some Scala constructs turned out to be very slow. So, I want to create some macro extensions to quickly complete these builds. But I can not submit more than one file.
Thanks!
source share