-
Notifications
You must be signed in to change notification settings - Fork 440
assertMacroExpansion always passes empty array as conformingTo
parameter of extension macros
#2031
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
Comments
Tracked in Apple’s issue tracker as rdar://113582092 |
@stephencelis Do you have an example where the extension is not included in the expanded source? Because the |
@ahoppen This might be a documentation problem, but the first example of an extension macro I found was this one in the Swift repo, which starts: These three lines of code make the macro expansion testing tool never add the conformance, presumably because macro expansion testing is totally decoupled from the library's macro declaration that specifies the allowed conformances. |
Ah, yes. That’s a current limitation of |
conformingTo
parameter of extension macros
@ahoppen if there is limitation in inferring conformance for a type, I would expect all the protocols that macro declares conformance for all provided. That way existing tests will not break when migrating to extension macro from member macro. |
The problem is that in |
The simplest approach is to pass this information as an extra parameter through assertMacroExpansion(
"""
@AddSendableExtension
struct MyType {
}
""",
expandedSource: """
struct MyType {
}
extension MyType: Sendable {
}
""",
macros: testMacros,
conformsTo: ["AddSendableExtension": ["Sendable"]],
indentationWidth: indentationWidth
) where the There are more advanced approaches I could imagine that, for example, depend on passing the actual macro declarations into @attached(extension, conformances: Sendable)
macro AddSendableExtension() = ... and then use the |
@ahoppen anything finalized on the approach yet, I am thinking of creating PR with @DougGregor's suggestion. |
Description
Previously a bug with conformance macros:
This issue has regressed with the change to extension macros.
Steps to Reproduce
The text was updated successfully, but these errors were encountered: