[swift-evolution] [Proposal] Nested extensions

Xiaodi Wu xiaodi.wu at gmail.com
Sat Apr 15 11:33:18 CDT 2017


The current rules in SE-0025 state that the access modifier in front of the
extension states both the default and the maximum allowed visibility. This
is what I was trying to change.

If private extension means that all members inside are by default and at
maximum only visible inside the extension, then every private extension
would be equivalent to `private extension Foo { }`. That is not useful, so
it is understood that private extension means private to the _containing_
scope. But the containing scope only has a name if the extension exists at
the top level.
On Sat, Apr 15, 2017 at 11:26 Xiaodi Wu <xiaodi.wu at gmail.com> wrote:

> The rules are laid out in SE-0025. What you are finding is that SE-0025 is
> not yet fully implemented.
> On Sat, Apr 15, 2017 at 11:04 Tino Heth <2th at gmx.de> wrote:
>
>> Am 15.04.2017 um 17:33 schrieb Xiaodi Wu <xiaodi.wu at gmail.com>:
>>
>> I think you misunderstand how access modifiers currently work with
>> extensions. It is not permitted to use an access modifier inside an
>> extension that is higher than that of the extension itself.
>>
>>
>> class Check {}
>>
>> fileprivate extension Check {
>> public func px() {
>> print("It compiles!")
>> }
>> }
>>
>> Check().px()
>>
>> This code executes without complains — but your example is right, it
>> fails if the extension is marked private… wtf? Access modifiers aren't even
>> mentioned in
>> https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Extensions.html#//apple_ref/doc/uid/TP40014097-CH24-ID151
>>
>> It really seems to me that the current extension-model is somewhat
>> broken; do you have a link to documentation of access levels for extensions?
>>
>> ```
>> private struct S {
>>   private extension {
>>     func f() { } // what is the access level of `f`?
>>   }
>> }
>> ```
>>
>> If `f` is private, then it is invisible outside the extension. But `f`
>> cannot be `fileprivate`, because `fileprivate` is more visible than the
>> private extension and is therefore not allowed.
>>
>> I'd simply say f is private and only visible inside the extension…
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170415/8bba8895/attachment.html>


More information about the swift-evolution mailing list