File tree Expand file tree Collapse file tree 3 files changed +11
-5
lines changed
SwiftCompilerPluginMessageHandling
SwiftSyntaxMacroExpansion
SwiftSyntaxMacros/MacroProtocols Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -168,7 +168,7 @@ private extension MacroRole {
168
168
case . memberAttribute: self = . memberAttribute
169
169
case . member: self = . member
170
170
case . peer: self = . peer
171
- case . conformance: self = . conformance
171
+ case . conformance: self = . extension
172
172
case . codeItem: self = . codeItem
173
173
case . extension: self = . extension
174
174
}
Original file line number Diff line number Diff line change @@ -251,7 +251,13 @@ public func expandAttachedMacroWithoutCollapsing<Context: MacroExpansionContext>
251
251
throw MacroExpansionError . declarationNotDeclGroup
252
252
}
253
253
254
- guard let extendedType = extendedType else {
254
+ let extensionOf : TypeSyntax
255
+ if let extendedType {
256
+ extensionOf = extendedType
257
+ } else if let identified = declarationNode. asProtocol ( IdentifiedDeclSyntax . self) {
258
+ // Fallback for old compilers with a new plugin, where
259
+ extensionOf = TypeSyntax ( SimpleTypeIdentifierSyntax ( name: identified. identifier) )
260
+ } else {
255
261
throw MacroExpansionError . noExtendedTypeSyntax
256
262
}
257
263
@@ -260,7 +266,7 @@ public func expandAttachedMacroWithoutCollapsing<Context: MacroExpansionContext>
260
266
let extensions = try attachedMacro. expansion (
261
267
of: attributeNode,
262
268
attachedTo: declGroup,
263
- providingExtensionsOf: extendedType ,
269
+ providingExtensionsOf: extensionOf ,
264
270
conformingTo: protocols,
265
271
in: context
266
272
)
Original file line number Diff line number Diff line change @@ -51,13 +51,13 @@ extension ConformanceMacro {
51
51
for (proto, whereClause) in newConformances {
52
52
let decl : DeclSyntax =
53
53
"""
54
- extension \( type. trimmed) : \( proto) {}
54
+ extension \( type. trimmed) : \( proto. trimmed ) {}
55
55
"""
56
56
57
57
var extensionDecl = decl. cast ( ExtensionDeclSyntax . self)
58
58
59
59
if let whereClause {
60
- extensionDecl = extensionDecl. with ( \. genericWhereClause, whereClause)
60
+ extensionDecl = extensionDecl. with ( \. genericWhereClause, whereClause. trimmed )
61
61
}
62
62
63
63
extensions. append ( extensionDecl)
You can’t perform that action at this time.
0 commit comments