-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Init Accessors not found by linker when used in another file #71578
Comments
It looks like the access level of init accessors are always set to swift/lib/AST/AccessRequests.cpp Lines 67 to 69 in a381589
The original proposal here implies the maximal access level could only be
IIUC
(And also teach type checker to respect these access levels so it emits some diagnostics when accessed incorrectly) @AnthonyLatsis Could you please give a hint on which way to take and assign this to me? Thank you! |
Apparently, this is a problem with the SIL linkage these cc @hborla. |
This case should be diagnosed during Sema, init accessors are not ABI and could only be used inside of the defining module. |
But they should work across files, right? (The report says they don’t either.) |
I was just replying to your comment. Regarding same module but different files - I think the discussion settled on allowing use of init accessors in extensions but in the same file, similar to property wrappers (if I remember correctly). Use cross files should be diagnosed just like cross module use. I think it might be worth it to look at the pitch/discussion thread on forums too. |
Sorry, I took your comment for a general one on the issue. This is the closest I got to finding anything related, but the post is about declaring, not using, @li3zhen1 While we’re waiting for clarification, let’s assume |
Seems like Should I add some additional check
|
I finally had a chance to take a look at what is going on with property wrappers and I think we wanted to make this a little bit broader for init accessors though and allow extensions in the same file where init accessor property is declared. Let's add a check to |
I think we also need semantic analysis to ignore the |
Holly says init accessors are supposed to be (at most) |
Description
When I try to use an Init Accessor in a file different from where they have been defined, my Swift Package stops compiling:
Reproduction
Taking example from https://github.com/apple/swift-evolution/blob/main/proposals/0400-init-accessors.md#proposed-solution:
If we just put
init(radians:)
in another file,ld
doesn't findAngle.radians.init : Swift.Double
anymore and the build crashes.Stack dump
Expected behavior
I would expect either to be able to use an Init Accessor in a separate file or receive a comprehensive compiler error message saying along the lines of "This is not possible, Init Accessors can only be used in the file where they have been declared" (if it's a known limitation).
Environment
Additional information
The text was updated successfully, but these errors were encountered: