Extend a specific type with extension macro

Hello - I'm looking to use an extension macro to add functionality to a concrete type.

public macro Mock = #externalMacro(module: "PluginTarget", type: "MockMacro")

struct Mocker {}

protocol Foo {}

// @Mock would add the following...
extension Mocker {
    func mockFoo(_ type: Foo.Protocol) -> Foo {
        // creates an instance of the given protocol

However, when I do so, I get the following warning:

⚠️ Extending a protocol composition is not supported; extending 'Foo' instead

Is there a way to specify that the extension macro will extend the Mocker type instead of Foo?

1 Like

I tried to use a PeerMacro, but got error "Macro expansion cannot introduce extension"

And this error is explained in this thread : "Macro expansion cannot introduce extension"? - #6 by Joe_Groff

1 Like