Skip to content

SyntaxProtocol.expand() does not expand conformance macros #1742

Closed
@tgoyne

Description

@tgoyne

Description

Conformance macros used in the input source are discarded without expansion. A basic example:

struct Conformance: ConformanceMacro {
    public static func expansion(
        of node: AttributeSyntax,
        providingConformancesOf declaration: some DeclGroupSyntax,
        in context: some MacroExpansionContext
    ) throws -> [(TypeSyntax, GenericWhereClauseSyntax?)] {
        fatalError()
    }
}
assertMacroExpansion("@Foo class Bar {}", expandedSource: "class Bar {\n}",
                     macros: ["Foo": Conformance.self])

This test passes despite the implementation being fatalError() due to expansion(of:performanceConformanceOf:in:) never being called. There appears to be two parallel implementations of macro expansion with ConformanceMacro only being supported in expandAttachedMacro(), which is not called by SyntaxProtocol.expand().

There may be other macro types not implemented as well; I did not try them all.

Steps to Reproduce

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions