I have a use case where I implement macro as generic type. The macro read data from a config module. These data have different variations and all conform to a protocol. That's why I implement it as a generic type.
At first I had the following in macro's compiler plugin file:
@main
struct macroPlugin: CompilerPlugin {
let providingMacros: [Macro.Type] = [
MyGenericMacro<FooConfig>.self,
]
}
and the following in macro interface file:
@attached(member, names: arbitrary)
public macro Foo() = #externalMacro(module: "myGenericMacroImpl", type: "MyGenericMacro<FooConfig>")
But compiler failed to find the macro in client code.
Then I created a type alias in macro pacakge:
public typealias FooMacro = MyGenericMacro<FooConfig>
and modified the above code to use the alias name. But client code still failed to find it.
Finally I had to create a wrapper struct and it worked this time.
public struct FooMacro: MemberMacro {
public static func expansion(
of node: AttributeSyntax,
providingMembersOf declaration: some DeclGroupSyntax,
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
try MyGenericMacro<FooConfig>.expansion(of: node, providingMembersOf: declaration, in: context)
}
}
I wonder if anyone saw similar issues? It seems a bug to me (though I have a hard time understanding why type alias doesn't work around it). Since this is probably just a corner case, I didn't create a bug report, but think it might be worth mentioning it here.