[swift-evolution] [Proposal] Nested extensions

Tino Heth 2th at gmx.de
Sat Apr 15 11:04:06 CDT 2017


> 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/5b5553ed/attachment.html>


More information about the swift-evolution mailing list