-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
ExtensionMacro extension methods are always (and incorrectly) fileprivate access only #69073
Comments
It looks like I'm running into this as well. My macro takes this:
and expands to this:
so I should be able to do this, since the macro provides a default implementation for every function:
but it only works in the same file. If I put it in a different file, the compiler says it does not conform. Adding the macro's expansion manually eliminates the error. I tried modifying my macro to explicitly mark the extension or its members as public/internal but it didn't help. |
Here is my macro. If you try to build ThrowingImplementationClient, you get an error in other.swift because the extension methods aren't visible. |
Ran into the exact same issue where the methods added by extension macro cannot be seen from another file. |
I suspect this was fixed by the second commit in #71717, but I haven't tested this theory yet |
I tested with main branch compiler and project indeed builds successfully with #71717. Can you use swift main branch snapshot for swift.org once it's older than Feb 20 to verify. |
ThrowingImplementation build successfully as well. |
Description
When using an attached ExtensionMacro to add an extension method to a protocol, that extension method is only visible in the file where the Macro attribute is applied, even when it should be internally visible by default (or following other explicit access control levels).
If I have all this in the same file it works.
But if I have the last line in a separate file, the extension method isn't visible even if I generated it specifically with an internal modifier
I suspect existing test cases for attached ExtensionMacros may have trouble catching this issue since the extension method is called in the same test file where the macro is applied (therefore never triggering the visibility issue). I'm attached a minimal example package here to demonstrate.
MyMacro.zip
Steps to reproduce
Expected behavior
I expect the extension method to be visible, autocomplete-suggested, and called at runtime. However, the compiler says the method doesn't exist.
Environment
swift-driver version: 1.87.2 Apple Swift version 5.9 (swiftlang-5.9.2.1.6 clang-1500.1.0.1.1)
Xcode 15.1 Build version 15C5028h
The text was updated successfully, but these errors were encountered: