swiftlang / swiftlang/swift-syntax

`assertMacroExpansion` should emit an error if macro is applied to node that is not a variable

Open
#2,207 2 comments 0 reactions 0 assignees View on GitHub
Macros
Dominant language
Swift
Stars
3.7k
Forks
553
Avg merge
5d 13h
Merged PRs (30d)
16

Description

When applying an accessor macro to e.g. a struct, `assertMacroExpansion` will currently happily swallow the attribute. It should, however, emit an error that accessor macros can’t be applied to structs. Ie. the following test case should emit an error.

```swift

func testAccessorOnStruct() {
struct TestMacro: AccessorMacro {
static func expansion(
of node: AttributeSyntax,
providingAccessorsOf declaration: some DeclSyntaxProtocol,
in context: some MacroExpansionContext
) throws -> [AccessorDeclSyntax] {
return []
}
}

assertMacroExpansion(
"@Test struct Foo {}",
expandedSource: "struct Foo {}",
macros: ["Test": TestMacro.self]
)
}
```

rdar://115562563

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.