@@ -136,7 +136,6 @@ class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
136136 || macro is MemberMacro . Type
137137 || macro is AccessorMacro . Type
138138 || macro is MemberAttributeMacro . Type
139- || macro is ConformanceMacro . Type
140139 || macro is ExtensionMacro . Type )
141140 }
142141
@@ -213,7 +212,7 @@ class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
213212
214213 if let declGroup = decl. asProtocol ( DeclGroupSyntax . self) {
215214 newItems. append (
216- contentsOf: expandConformances ( of: declGroup) . map {
215+ contentsOf: expandExtensions ( of: declGroup) . map {
217216 newDecl in CodeBlockItemSyntax ( item: . decl( newDecl) )
218217 }
219218 )
@@ -429,45 +428,29 @@ extension MacroApplication {
429428 // If any of the custom attributes associated with the given declaration
430429 // refer to conformance macros, expand them and return the resulting
431430 // set of extension declarations.
432- private func expandConformances ( of decl: DeclGroupSyntax ) -> [ DeclSyntax ] {
433- let extendedType : Syntax
431+ private func expandExtensions ( of decl: DeclGroupSyntax ) -> [ DeclSyntax ] {
432+ let extendedType : TypeSyntax
434433 if let identified = decl. asProtocol ( IdentifiedDeclSyntax . self) {
435- extendedType = Syntax ( identified. identifier. trimmed)
434+ extendedType = " \ ( identified. identifier. trimmed) "
436435 } else if let ext = decl. as ( ExtensionDeclSyntax . self) {
437- extendedType = Syntax ( ext. extendedType. trimmed)
436+ extendedType = " \ ( ext. extendedType. trimmed) "
438437 } else {
439438 return [ ]
440439 }
441440
442441 var extensions : [ DeclSyntax ] = [ ]
443- let macroAttributes = getMacroAttributes ( attachedTo: decl. as ( DeclSyntax . self) !, ofType: ConformanceMacro . Type. self)
444- for (attribute, conformanceMacro) in macroAttributes {
445- do {
446- let newConformances = try conformanceMacro. expansion ( of: attribute, providingConformancesOf: decl, in: context)
447-
448- for (type, whereClause) in newConformances {
449- var ext : DeclSyntax = """
450- extension \( extendedType) : \( type) { }
451- """
452- if let whereClause {
453- ext = DeclSyntax ( ( ext. cast ( ExtensionDeclSyntax . self) ) . with ( \. genericWhereClause, whereClause) )
454- }
455-
456- extensions. append ( DeclSyntax ( ext) )
457- }
458- } catch {
459- context. addDiagnostics ( from: error, node: attribute)
460- }
461- }
462442
463443 let extensionMacroAttrs = getMacroAttributes ( attachedTo: decl. as ( DeclSyntax . self) !, ofType: ExtensionMacro . Type. self)
464- let extendedTypeSyntax = TypeSyntax ( " \( extendedType. trimmed) " )
465444 for (attribute, extensionMacro) in extensionMacroAttrs {
466445 do {
446+ // FIXME: We need a way for unit tests of extension macros to
447+ // specify protocols already stated in source (e.g. as arguments
448+ // to `assertMacroExpansion`).
467449 let newExtensions = try extensionMacro. expansion (
468450 of: attribute,
469451 attachedTo: decl,
470- providingExtensionsOf: extendedTypeSyntax,
452+ providingExtensionsOf: extendedType,
453+ conformingTo: [ ] ,
471454 in: context
472455 )
473456
0 commit comments