-
Notifications
You must be signed in to change notification settings - Fork 418
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
MacroExpansionContext.lexicalContext always empty for freestanding macros? #2907
Comments
Synced to Apple’s issue tracker as rdar://140829016 |
Are you seeing the empty lexical context when testing the macro using |
I'm using the swift-macro-testing library of point-free in my tests, because when I wrote tests with But I did try it in a real-world project too, and the result was exactly the same as with the macro-testing library. For your convenience, I attached a full minimal Swift package with which you can reproduce the exact problem I'm reporting here by simply running the tests. I've also added an |
Thanks for providing the reproducing project. It looks like there are two independent issues:
I’m going to close this issue because we are already tracking (1) and (2) is not an issue with swift-syntax itself. Feel free to re-open it if I missed anything. |
@ahoppen Thank you for the quick response and the explanation! After you said that the Of course, returning |
Description
I am currently writing a freestanding macro using version
600.0.1
which needs to read some information about its enclosing code. According to this thread on the forums @DougGregor has implemented exactly what I need in #1554 inside thelexicalContext
property. But when I callcontext.lexicalContext
I always get an empty array, even though my freestanding macro is placed inside a SwiftUIbody
within aButton
initializer like this:The purpose of my macro is to auto-generate a semantic localization key based on the context. The expected expansion:
I got everything working, except that I can't access the context. I would expect
lexicalContext
to be something like["Button", "body", "MyView"]
or at least contain these texts in some kind of structure so I can read them out. But it's completely empty for me. Am I missing something?Steps to Reproduce
This is the helper function in my
ExpressionMacro
I'm trying to implement:The text was updated successfully, but these errors were encountered: