When applying an attached member macro to e.g. a variable, assertMacroExpansion will currently happily swallow the attribute. It should, however, emit an error that member macros can’t be applied to variables (specifically, if the declaration is not a DeclGroupSyntax). Ie. the following test case should emit an error.
func testMemberMacroOnVar() {
struct TestMacro: MemberMacro {
static func expansion(
of node: AttributeSyntax,
providingMembersOf declaration: some DeclGroupSyntax,
conformingTo protocols: [TypeSyntax],
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
return []
}
}
assertMacroExpansion(
"""
@Test var x: Int
""",
expandedSource: """
var x: Int
""",
macros: [
"Test": TestMacro.self
]
)
}
rdar://115562663
When applying an attached member macro to e.g. a variable,
assertMacroExpansionwill currently happily swallow the attribute. It should, however, emit an error that member macros can’t be applied to variables (specifically, if the declaration is not aDeclGroupSyntax). Ie. the following test case should emit an error.rdar://115562663