[swift-evolution] Fix "private extension" (was "Public Access Modifier Respected in Type Definition")

David Sweeris davesweeris at mac.com
Mon Oct 2 21:08:19 CDT 2017


> On Oct 2, 2017, at 6:52 PM, Tony Allevato via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Thanks for hoisting this out into its own thread, Jordan. I was hesitant to elaborate more on another access level thread :)
> 
> I think the change should absolutely be made. Even though the "private" keyword occurs at the file level, the description of the feature in the Swift documentation simply states: "you can mark an extension with an explicit access-level modifier to set a new default access level for all members defined within the extension." To me, that implies that "private extension Foo { func bar() }" should be identical to "extension Foo { private func bar() }", but today it becomes equivalent to "extension Foo { fileprivate func bar() }".
> 
> That seems fundamentally broken, because (1) it's inconsistent, (2) "private extension" and "fileprivate extension" are two ways of saying the same thing, non-intuitively, and (3) there's no way for someone to use the shorthand syntax to take advantage of the new meaning of private within same-file type extensions.
> 
> While I personally never use the shorthand extension access level feature (because I prefer the explicit form, and because of situations like this one), I definitely think it should be consistent for people who do want to use it.
> 
> I wonder how much existing code would be affected by this change. Do people use "private extension" when they really want "fileprivate extension"? I would hope the number of users affected would be few, at least.

I don’t think I’ve ever used “private extension”, but if I did, I’d expect it to not mean “fileprivate extension”.

- Dave Sweeris 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171002/197b1727/attachment.html>


More information about the swift-evolution mailing list