-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SyntaxProtocol.expand() does not expand peer macros introduced by other macros #1805
Comments
Tracked in Apple’s issue tracker as rdar://110923449 |
|
In When expanding a This can be reproduced in the following example: struct MyMemberMacro: MemberMacro {
static func expansion<Declaration, Context>(
of node: AttributeSyntax,
providingMembersOf declaration: Declaration,
in context: Context
) throws -> [DeclSyntax] where Declaration : DeclGroupSyntax, Context : MacroExpansionContext {
[
"""
func doSomething() {
#myFreestandingMacro
}
"""
]
}
}
struct MyFreestandingMacro: ExpressionMacro {
static func expansion<Node, Context>(
of node: Node,
in context: Context
) throws -> ExprSyntax where Node : FreestandingMacroExpansionSyntax, Context : MacroExpansionContext {
#"print("Hello World")"#
}
}
struct MyDeclarationMacro: DeclarationMacro {
static func expansion<Node, Context>(
of node: Node,
in context: Context
) throws -> [DeclSyntax] where Node : FreestandingMacroExpansionSyntax, Context : MacroExpansionContext {
[
"""
func doSomething() {
#myFreestandingMacro
}
"""
]
}
}
final class MacroTests: XCTestCase {
func testExpansionOfFreestandingMacroInMemberMacro() {
assertMacroExpansion(
"""
@MyMemberMacro
struct Foo {
}
""",
expandedSource: """
struct Foo {
func doSomething() {
print("Hello World")
}
}
""",
macros: [
"MyMemberMacro": MyMemberMacro.self,
"myFreestandingMacro": MyFreestandingMacro.self
]
)
}
func testExpansionOfFreestandingMacroInFreestandingMacro() {
assertMacroExpansion(
"""
struct Foo {
#myDeclarationMacro
}
""",
expandedSource: """
struct Foo {
func doSomething() {
print("Hello World")
}
}
""",
macros: [
"myDeclarationMacro": MyDeclarationMacro.self,
"myFreestandingMacro": MyFreestandingMacro.self
]
)
}
} The second test fails with the following:
I'd expect the levels of expansion to be consistent either way so i'm wondering if this was intentional or worth addressing before the final 5.9 release? |
Description
This test fails due to
Foo
not having the secondbar
field (whileBar
passes). This works correctly when expanded by the compiler plugin (although in this example it obviously result in a compilation error due to the property being redeclared).Steps to Reproduce
No response
The text was updated successfully, but these errors were encountered: