[swift-evolution] access control proposal

Marc Knaup marc at knaup.koeln
Mon Dec 14 12:22:08 CST 2015


Well that would break the pattern where you split the implementation of a
type across several extensions in the same file.
This is also often done when declaring protocol conformance to break down
the type into logical pieces.
I don't want to be forced to squeeze everything into the same body and
declare a list of a dozen protocol conformance at once.
On Dec 14, 2015 19:10, "Matthew Johnson" <matthew at anandabits.com> wrote:

>
> On Dec 14, 2015, at 11:58 AM, Marc Knaup <marc at knaup.koeln> wrote:
>
> To sum up (what I understand) the new access modifier
>
>    - can be used only on type members (properties, methods, initializers,
>    subscripts and nested types) - so not at file-level
>    - grants access to that symbol to
>       - the containing type
>       - (nested types)?
>       - extension in the same file
>    - and does not grant access to
>       - extensions declared in a different file
>       - subclasses
>       - other locations in the same file as the ones granted above
>
> Did I forget anything?
>
>
> This is *not* correct.  It only grants access to other members declared
> within the same body.  Some examples may help clarify the concept:
>
> struct S {
>     // visible within the struct declaration only and *nowhere* else
>     scoped let foo: String
>
>     struct T {
>         // still within the scope of S so foo is still visible here
>         // buzz is only visible within the inner type, buzz is not visible
> to members of S
>         scoped let buzz: String
>     }
> }
>
> // in same file
> extension S {
>     // foo is not visible here
>     // bar is visible only within the extension in which it is declared
> and *nowhere* else
>     scoped fun bar() -> String
> }
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151214/83ae5a00/attachment.html>


More information about the swift-evolution mailing list