1

I have these three macros all defined in the same file (and with the same exact definition):

class client(val port: Int = 9000) extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro ClientGen.mkClient
}

class grpcMock(val port: Int = 9000) extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro ClientGen.mkClient 
}

class foo(val port: Int = 9000) extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro ClientGen.mkClient
}

There are absolutely no differences between them other than the names ... However:

  • @client object Foo works fine
  • @grpcMock object Foo fails with not found type: grpcMock
  • @foo object Foo fails with invalid annotation new foo()

I am lost :( Does anyone have an idea what can be wrong here?

Basically, all annotations I had in that file before today, still work. Any new one I try to add complains about invalid annotation unless it's name looks like grpcMock, in which case it says "type not found". What's going on here???

11
  • Did you do sbt clean compile (for subproject with macro annotations and subproject with Foo)? Do you have reproduction? What is ClientGen.mkClient? Commented Apr 25 at 3:17
  • Switch on scalacOptions += "-Ymacro-debug-lite" to see how macros are expanded. What is the output upon compilation? Commented Apr 25 at 3:18
  • Annotate definitions of macro annotations with @compileTimeOnly("Enable macro annotations") to make sure that they are expanded during compilation Commented Apr 25 at 3:26
  • scastie.scala-lang.org/DmytroMitin/7n1o84KVRpS3dOC8nP5IUg/2 Commented Apr 25 at 3:43
  • 1
    @DmytroMitin Ok, I figured it out. The "Invalid annotation" thing was indeed coming from the "ClientGen" implementation (it expects macro name to be client). Sorry for sending you on the wild goose chase :( I was sure that I replaced it with noop, but ... I haven't :( The "type not found" error was real though. I'll post an answer to explain in case you are curious. Commented Apr 25 at 15:38

1 Answer 1

3

Ok, I figured it out. The "Invalid annotation" thing was coming from the macro implementation (it wants the macro to be "client" explicitly).

The "type not found" error was real. It was caused by the Mac's case-insensititve filesystem.
The real macro implemenation looked like this:

class grpcMock(val port: Int = 9000) extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro GrpcMock.mkMock 
}

And that does not work because compiled class GrpcMock overrides grpcMock on disk.
Cannot have two classes whose names differ only in case on Mac.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.