Skip to content

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

Open
@ahoppen

Description

@ahoppen

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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    MacrosIssues in the SwiftSyntaxMacro… modules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions