Skip to content

Body macro can’t be attached to variables #75715

Open
@ahoppen

Description

@ahoppen

The function body macro proposal states:

When using the shorthand syntax for get-only properties, a function body macro can be applied to the property itself:

But the following does not compile

@stringify // error: 'body' macro cannot be attached to var ('x')
var x: Int { 2 }

With stringify being a function body macro.

Attaching a function body macro to a getter also doesn’t work:

var x: Int {
  @stringify get { 1 } // error: Declaration is not a type with an optional code block
}

rdar://130739935

MyMacro.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    swift macroFeature → declarations: Swift `macro` declarations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions