@@ -136,7 +136,6 @@ class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
136
136
|| macro is MemberMacro . Type
137
137
|| macro is AccessorMacro . Type
138
138
|| macro is MemberAttributeMacro . Type
139
- || macro is ConformanceMacro . Type
140
139
|| macro is ExtensionMacro . Type )
141
140
}
142
141
@@ -213,7 +212,7 @@ class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
213
212
214
213
if let declGroup = decl. asProtocol ( DeclGroupSyntax . self) {
215
214
newItems. append (
216
- contentsOf: expandConformances ( of: declGroup) . map {
215
+ contentsOf: expandExtensions ( of: declGroup) . map {
217
216
newDecl in CodeBlockItemSyntax ( item: . decl( newDecl) )
218
217
}
219
218
)
@@ -429,45 +428,29 @@ extension MacroApplication {
429
428
// If any of the custom attributes associated with the given declaration
430
429
// refer to conformance macros, expand them and return the resulting
431
430
// 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
434
433
if let identified = decl. asProtocol ( IdentifiedDeclSyntax . self) {
435
- extendedType = Syntax ( identified. identifier. trimmed)
434
+ extendedType = " \ ( identified. identifier. trimmed) "
436
435
} else if let ext = decl. as ( ExtensionDeclSyntax . self) {
437
- extendedType = Syntax ( ext. extendedType. trimmed)
436
+ extendedType = " \ ( ext. extendedType. trimmed) "
438
437
} else {
439
438
return [ ]
440
439
}
441
440
442
441
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
- }
462
442
463
443
let extensionMacroAttrs = getMacroAttributes ( attachedTo: decl. as ( DeclSyntax . self) !, ofType: ExtensionMacro . Type. self)
464
- let extendedTypeSyntax = TypeSyntax ( " \( extendedType. trimmed) " )
465
444
for (attribute, extensionMacro) in extensionMacroAttrs {
466
445
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`).
467
449
let newExtensions = try extensionMacro. expansion (
468
450
of: attribute,
469
451
attachedTo: decl,
470
- providingExtensionsOf: extendedTypeSyntax,
452
+ providingExtensionsOf: extendedType,
453
+ conformingTo: [ ] ,
471
454
in: context
472
455
)
473
456
0 commit comments