Skip to content

Commit 8e44846

Browse files
committed
[Macros] Add test case for #67989 / rdar://114105615.
The bug described by this report has been fixed on main. Add a test case to ensure that it doesn't regress.
1 parent baa20ae commit 8e44846

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

test/Macros/Inputs/syntax_macro_definitions.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,25 @@ public struct EquatableViaMembersMacro: ExtensionMacro {
13431343
}
13441344
}
13451345

1346+
public struct FooExtensionMacro: ExtensionMacro {
1347+
public static func expansion(of node: AttributeSyntax, attachedTo declaration: some DeclGroupSyntax, providingExtensionsOf type: some TypeSyntaxProtocol, conformingTo protocols: [TypeSyntax], in context: some MacroExpansionContext) throws -> [ExtensionDeclSyntax] {
1348+
let decl: DeclSyntax =
1349+
"""
1350+
extension Foo {
1351+
var foo: String { "foo" }
1352+
func printFoo() {
1353+
print(foo)
1354+
}
1355+
}
1356+
"""
1357+
guard let extensionDecl = decl.as(ExtensionDeclSyntax.self) else {
1358+
return []
1359+
}
1360+
1361+
return [extensionDecl]
1362+
}
1363+
}
1364+
13461365
public struct ConformanceViaExtensionMacro: ExtensionMacro {
13471366
public static func expansion(
13481367
of node: AttributeSyntax,

test/Macros/macro_expand_extensions.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,22 @@ func testMakeMeHashable(mmh: MakeMeHashable, dict: [MakeMeHashable: Int]) {
216216

217217
@ImpliesHashable
218218
public struct MakeMeHashable { }
219+
220+
221+
// https://github.com/apple/swift/issues/67989 - member added via extension
222+
// to a protocol is not visible
223+
224+
@attached(extension, names: named(foo), named(printFoo))
225+
public macro FooExtension() = #externalMacro(module: "MacroDefinition", type: "FooExtensionMacro")
226+
227+
@FooExtension
228+
protocol Foo {
229+
var foo: String { get }
230+
}
231+
232+
extension String: Foo { }
233+
234+
func testStringFoo(s: String) {
235+
"Test".printFoo()
236+
s.printFoo()
237+
}

0 commit comments

Comments
 (0)