I'm trying to add protocol conformance with a macro
The macro is defined as:
protocol Prot {}
@attached(extension, conformances: Prot)
public macro MyMacro = #externalMacro(module: "MyMacro", type: "MyMacro")
where MacroName
is defined as:
struct MyMacro: ExtensionMacro {
public static func expansion(of node: AttributeSyntax,
attachedTo declaration: some DeclGroupSyntax,
providingExtensionsOf type: some TypeSyntaxProtocol,
conformingTo protocols: [TypeSyntax], in context: some MacroExpansionContext) throws -> [ExtensionDeclSyntax] {
// guard !protocols.isEmpty else {
// return []
// }
return [try ExtensionDeclSyntax("extension \(type.trimmed): Prot {}") ]
}
}
The macro expands correctly adding the extension with the protocol conformance declaration correctly However, when I build the code (not the macro plugin, that builds fine) I get an error:
Conformance to 'Prot' is not covered by macro 'MyMacro'
Not sure how to solve this error? Anyone have a hint how to properly add protocol conformance using a macro?
Incidentally, if I uncomment the guard statement I see that protocols is empty