# Declaration name is not covered by macro

**URL:** <https://forums.swift.org/t/declaration-name-is-not-covered-by-macro/72054>\
**Category:** Using Swift\
**Tags:** macros, attached-macros\
**Created:** [May 24, 2024, 2:00pm UTC](https://forums.swift.org/t/declaration-name-is-not-covered-by-macro/72054 "2024-05-24T14:00:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![al-skobelev](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/al-skobelev/32/35552_2.png) [@al-skobelev](https://forums.swift.org/u/al-skobelev)\
**Post date:** [May 24, 2024, 2:00pm UTC](https://forums.swift.org/t/declaration-name-is-not-covered-by-macro/72054/1 "2024-05-24T14:00:11Z")

</div>

Hello!

I'm trying to generate a protocol dependent for another one using Swift macros. The implementation looks like the following:

```swift
@attached (peer, names: suffixed (Dependent),prefixed (svc))
public macro dependableService() = #externalMacro (module: "Macros", type: "DependableServiceMacro")

```

```swift
public struct DependableServiceMacro: PeerMacro
{
    public static func expansion (of node: AttributeSyntax,
             providingPeersOf declaration: some DeclSyntaxProtocol,
                               in context: some MacroExpansionContext)
        throws -> [DeclSyntax]
    {
        guard let baseProto = declaration.as (ExtensionDeclSyntax.self)
        else {
            return []
        }

        let nm = baseProto.extendedType.trimmedDescription
        let protoNm = nm + "Dependent"
        let varNm = "svc" + nm

        let protoDecl: DeclSyntax =
            """
            protocol \(raw: protoNm) : ServiceDependent {
                var \(raw: varNm) : \(raw: nm) { get set }
            }
            """
        return [protoDecl]
    }
}

```

When I try using it in my code like this

```swift
@dependableService extension MyService {}

```

the macro correctly expands to the following text:

```swift
protocol MyServiceDependent : ServiceDependent {
    var svcMyService : MyService {
        get
        set
    }
}

```

However, the compiler gives me the error:

```swift
error: declaration name 'MyServiceDependent' is not covered by macro 'dependableService'
protocol MyServiceDependent : ServiceDependent {
         ^

```

Do I understand correctly, that for some reason the compiler cannot deduce the name of the generated protocol based on the name of the extensible protocol, despite the presence of the names: suffixed(Dependent) attribute in the macro declaration?

Could anybody please tell me what I'm doing wrong here?

Thanks in advance
