Skip to content

[Macros] Implement expansion of conformance macros #1773

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 2 commits into from
Jun 14, 2023

Conversation

DougGregor
Copy link
Member

Somehow, we forgot to implement this here, even though the compiler has supported it for a long time.

Fixes #1742 / rdar://110418242.

Somehow, we forgot to implement this here, even though the compiler has
supported it for a long time.

Fixes swiftlang#1742 / rdar://110418242.
@DougGregor
Copy link
Member Author

@swift-ci please test

extension \(raw: identifier): \(type) { }
"""
if let whereClause {
ext = DeclSyntax((ext.as(ExtensionDeclSyntax.self))!.with(\.genericWhereClause, whereClause))
Copy link
Member

Choose a reason for hiding this comment

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

Slightly nicer version in my opinion would be

Suggested change
ext = DeclSyntax((ext.as(ExtensionDeclSyntax.self))!.with(\.genericWhereClause, whereClause))
ext = DeclSyntax((ext.cast(ExtensionDeclSyntax.self)).with(\.genericWhereClause, whereClause))

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you, I've pulled this in!

// refer to conformance macros, expand them and return the resulting
// set of extension declarations.
private func expandConformances(of decl: DeclGroupSyntax) -> [DeclSyntax] {
let identifier: String
Copy link
Member

Choose a reason for hiding this comment

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

Why not make identifier: Syntax and then you don’t need to convert to strings or use the raw interpolation below. Also identifier isn’t correct because ext.extendedType is not an identifier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great point, I've updated this code.

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test Windows

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() does not expand conformance macros
2 participants