Skip to content

Don’t remove #if attributes with AttributeRemover #2945

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

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jan 20, 2025

Fixes #2923
rdar://141840779

@ahoppen ahoppen requested a review from bnbarham as a code owner January 20, 2025 16:07
@ahoppen
Copy link
Member Author

ahoppen commented Jan 20, 2025

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Jan 21, 2025

@swift-ci Please test Windows

for case .attribute(let attribute) in node {
for attribute in node {
guard case .attribute(let attribute) = attribute else {
filteredAttributes.append(attribute)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if #if ... #endif contained attributes matching self.predicate(attribute)? Or it never happens because MacroSystem doesn't support #if attributes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought is that MacroSystem doesn’t know how to evaluate #if conditions, so just keeping them verbatim is the best we can do…

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see MacroApplication.macroAttributes(attachedTo:) doesn't look into #if at all at this point. So yeah, this is fine.

@ahoppen ahoppen merged commit b90cdca into swiftlang:main Jan 27, 2025
3 checks passed
@ahoppen ahoppen deleted the keep-pound-if-attribute branch January 27, 2025 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SyntaxProtocol.expand(macros:) drops IfConfigDeclSyntax nodes from result
2 participants