Basic macro annotation not compiling; 2.13.8 with `Ymacro-annotations`

So I’m trying to learn how to use macros and I’m unable to get the “basic” example from the website to compile

Following : Macro Annotations | Macros | Scala Documentation

I have a file that looks like this

import scala.annotation.{StaticAnnotation, compileTimeOnly}
import scala.language.experimental.macros
import scala.reflect.macros.whitebox

// I commented this out to make sure I was overriding the message 
//@compileTimeOnly("enable macro paradise to expand macro annotations")
class identity extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro identityMacro.impl
}

object identityMacro {
  def impl(c: whitebox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
    import c.universe._
    val inputs = annottees.map(_.tree).toList
    val (annottee, expandees) = inputs match {
      case (param: ValDef) :: (rest @ (_ :: _)) => (param, rest)
      case (param: TypeDef) :: (rest @ (_ :: _)) => (param, rest)
      case _ => (EmptyTree, inputs)
    }
    println((annottee, expandees))
    val outputs = expandees
    c.Expr[Any](Block(outputs, Literal(Constant(()))))
  }
}

@identity
class Foo {}

but when I run it with what I believe is the right flag I get back an error saying that I’m missing the flag:

λ  ~/Sandbox/scalamacros  scalac -version
Scala compiler version 2.13.8 -- Copyright 2002-2021, LAMP/EPFL and Lightbend, Inc.
λ  ~/Sandbox/scalamacros  scalac -Ymacro-annotations atest.scala
atest.scala:26: error: macro annotation could not be expanded (since these are experimental, you must enable them with -Ymacro-annotations)
class Foo {}
      ^
1 error

scalac came from coursier if that makes a difference.

I feel like I’m missing something super obvious, has anyone else encountered this?

ps: If this is the wrong place for this question, could someone point me to the correct place? I came here from github.com/scala/bug contribution guide

I suspect that you have to compile the definition of the macro annotation separately from the code where you use the macro.

So that means putting

@identity
class Foo {}

in another file. First compile the file with the macro. Then compile the other file, with the class files of the previous compilation on the classpath. But for anything more than a “hello world” I would use a sbt project, with one submodule for your macros and one submodule for the code that depends on the macros. Even for a “simple” example that might be a better idea than manually invoking scalac.

that makes a lot of sense; l et me give a whirl.

Thanks for speedy reply!

For any future web searcher, I did as @Jasper-M suggested and it worked as expected:

λ  ~/Sandbox/scalamacros  scalac -Ymacro-annotations atest.scala
λ  ~/Sandbox/scalamacros  scalac -Ymacro-annotations btest.scala
FROM MACRO:
(<empty>,List(class Foo extends scala.AnyRef {
  def <init>() = {
    super.<init>();
    ()
  }
}))

Makes sense, I can’t try and define something and then try and use it in the same file