[swift-evolution] [Discussion] A Problem With SE-0025?

Matthew Johnson matthew at anandabits.com
Wed Jun 29 17:50:15 CDT 2016


> On Jun 29, 2016, at 5:33 PM, Michael Peternell via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> Am 30.06.2016 um 00:17 schrieb Xiaodi Wu via swift-evolution <swift-evolution at swift.org>:
>> 
>> Here is the problem:
>> 
>> ```
>> private struct Foo {
>>  /* private */ struct Bar {
>>    // it doesn't matter what you write in here, you'll never see it in `Foo`
>>  }
>> }
>> ```
>> 
> 
> So this is not a practical design for this feature then. Following the ideas I presented a few hours earlier this should lead to:
> 
> private struct Foo {
>    struct Bar {
>        var strawberryBar: [String]
>    }
>    // Scope(Bar) = Scope(Foo), because the scope of Bar is unspecified
>    // Scope(Bar.strawBerryBar) = Scope(Bar) = Scope(Foo), for the same reason
>    // Foo is visible here => Bar.strawberryBar is visible too
> 
>    func hello() {
>        let s = Bar(strawberryBar: ["yummi"]
>        print("mjam: \(s.strawberryBar)")
>    }
>    // everything compiles...
> }
> 
> Making Bar implicitly private doesn't make sense at all. Bar should have the same scope as Foo. `private` on Bar has a completely different meaning than `private` on Foo so this is not the same access level. The implicit access level of Bar is unutterable here.
> 
> Anyways... I'm out. I think there *is* a possible design that works. As long as no one provides another (possibly better) solution or argues with my why my design can not work I see no point (for me) in continuing this discussion.

What you expect here is exactly what is intended by SE-0025 and provided by Jordan’s amendment.  I think some there is some confusion around access modifiers vs visibility.  In Swift 2 these always happened to correspond.  That correspondence allowed you to simple copy and paste any access modifier present on a parent scope into a nested declaration and it wouldn’t ever lower the visibility of the member (although it could raise it in the case of `public`).  Further, anywhere an access modifier appeared it referred to the same level of visibility.  

In Swift 3 with the scope-based `private` this is no longer the case - if you copy and paste `private` from a parent scope into a nested declaration it lowers the visibility because `private` is applied in a narrower scope.  The meaning of the access modifier and therefor the visibility level it references depend on the context (scope) in which the modifier appears.  This has caused some confusion.  The fact that the visibility is unutterable exacerbates the confusion.

-Matthew

> 
> -Michael
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list