"Recursive expansion of macro"?

I have a macro that, when applied to a type, applies the same macro to nested types. E.g.,

@MyMacro
struct Foo {
  struct Bar {
  }
}

Should expand to:

-@MyMacro
 struct Foo {
+  @MyMacro
   struct Bar {
   }
 }

And so on.

Using a member attribute macro would seem to make this straightforward, but I get a "Recursive expansion of macro" error. I can see wanting some limitation on recursion to prevent the compiler from going into a tailspin, but it seems like it should work at some limited capacity.

Is this a bug worth filing or is this limitation by design?

5 Likes