Make private members accessible by extensions within the same module

An issue I encounter frequently is the desire to break up a large class / struct across multiple files - e.g. I might have:
Where I group logically related extensions. However, I'm often frustrated that I can't access the type's private members within my module. So my options are to either expose internally implementation details I don't need to, or stuff everything into one file which can make things hard to read, and allow coupling I'd like to prevent. I'd like to propose allowing extensions to access their private members from anywhere within a module.

For the most part, access control changes are pretty much off the table at this point. But I would do a search on the forums, since this topic has been discussed extensively, and is somewhat of a sore topic now. I don't believe people came up with a consensus, as much of this discussion is going to lead to the dreaded submodule/namespacing debates.


I'm not looking to introduce any new access control levels, or namespace keywords. I'm just looking to relax the meaning of private as was done with the swift 3 -> 4 transition:

I.e. fileprivate means, visible to everyone in this file regardless of type while private would mean, visible to this type within this module. (Whereas it currently means, visible to this type within this file which I believe hurts its utility.)

I'm just saying, this topic has previously been brought up, and is very much scorched Earth. You should read up on those previous topics to see what the feedback was, but lot of people are unhappy with how access control is, but no one agrees on a solution, so it is probably going to stay how it is for the foreseeable future.

1 Like

Even if access control were not scorched earth, this would be an improbable change, because, IIRC the core team has stated that access levels should be strictly ordered:
That is if you can access some private thing, than you should be able to access it in all of the same places were it to become fileprivate.
It was possible to expand private to file-scoped extensions, because file-scoped extensions are still strictly smaller than the whole file.