Skip to content
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

Body macro can’t be attached to variables #75715

Open
ahoppen opened this issue Aug 6, 2024 · 0 comments
Open

Body macro can’t be attached to variables #75715

ahoppen opened this issue Aug 6, 2024 · 0 comments
Labels
swift macro Feature → declarations: Swift `macro` declarations

Comments

@ahoppen
Copy link
Contributor

ahoppen commented Aug 6, 2024

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

@ahoppen ahoppen added the swift macro Feature → declarations: Swift `macro` declarations label Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
swift macro Feature → declarations: Swift `macro` declarations
Projects
None yet
Development

No branches or pull requests

1 participant