Conformance to 'X' is not covered by macro 'Y' with Swift extension macro

205 views Asked by At

With this macro:

// Definition:
@attached(extension, names: arbitrary)
public macro AutoDomainError() = #externalMacro(module: "...", type: "...")

// Implementation:
public struct AutoDomainErrorMacro: ExtensionMacro {
    public static func expansion(
        of node: SwiftSyntax.AttributeSyntax,
        attachedTo declaration: some SwiftSyntax.DeclGroupSyntax,
        providingExtensionsOf type: some SwiftSyntax.TypeSyntaxProtocol,
        conformingTo protocols: [SwiftSyntax.TypeSyntax],
        in context: some SwiftSyntaxMacros.MacroExpansionContext
    ) throws -> [SwiftSyntax.ExtensionDeclSyntax] {
        let extensionDecl = try ExtensionDeclSyntax("extension \(type.trimmed): FormatableDomainError") {
        }
        
        return [extensionDecl]
    }
}

and this code in the main.swift file:

protocol FormatableDomainError {
    
}

@AutoDomainError
enum TestError {
    case testErrorCase
}
// Code generated by the macro:
// extension TestError: FormatableDomainError { 
// }

I'm getting this compilation error: Conformance to 'FormatableDomainError' is not covered by macro 'AutoDomainError' on the code generated by the macro.

The code produced by the macro look perfectly fine to me so I don't get the error. I tried playing with the names and conformances parameters of the @attached macro but nothing seems to work.

0

There are 0 answers