"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?

10 Likes

I'm having this issue, despite my nested macro only being applied one layer down like in your example.

Did you find a workaround / solution to this?

It's not pretty, but you could alias @MyMacro to @MyMacro2 and so on and apply them with an incremented number at each layer.

2 Likes