<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 29, 2016 at 5:25 PM, Matthew Johnson <span dir="ltr">&lt;<a href="mailto:matthew@anandabits.com" target="_blank">matthew@anandabits.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div><div class="h5"><blockquote type="cite"><div>On Jun 29, 2016, at 4:30 PM, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 29, 2016 at 4:15 PM, Jordan Rose <span dir="ltr">&lt;<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span><br><div><blockquote type="cite"><div>On Jun 29, 2016, at 14:12, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 29, 2016 at 4:07 PM, Jordan Rose <span dir="ltr">&lt;<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span><br><div><blockquote type="cite"><div>On Jun 29, 2016, at 14:03, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 29, 2016 at 3:15 PM, Jordan Rose via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><br>
<br>
&gt; On Jun 29, 2016, at 13:13, Jose Cheyo Jimenez &lt;<a href="mailto:cheyo@masters3d.com" target="_blank">cheyo@masters3d.com</a>&gt; wrote:<br>
&gt;<br>
&gt; I know this might be have been brought up before but<br>
&gt;<br>
&gt; why not just disallow the “private&quot; keyword for top level types, extensions etc.<br>
&gt;<br>
&gt; A fixit could change top level `private` to `fileprivate`.<br>
&gt;<br>
&gt; I think this is a little less confusing since effectively this is what is happening in the background.<br>
<br>
</span>That doesn’t fix anything for inner types, so it’s a lot less important than the rest of the amendment.<br>
<br>
There actually is an answer to this, which is that the core team expects &#39;private&#39; to be the common keyword, and therefore it’s better if you can use it at the top level and ignore ‘fileprivate’ altogether in most programs.<br></blockquote><div><br></div><div>On second thought, wouldn&#39;t all of this be inapplicable if `private` literally meant visibility *only* within the current declaration, and neither outside it nor inside any nested types, etc.?</div></div></div></div></div></blockquote><br></div></span><div>Yes, but that&#39;s not very useful:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>public struct Foo {</div><div>  private var value: Int = 0</div><div>  public func test() {</div><div>    print(value) // error</div><div>  }</div><div>}</div></blockquote><div><br></div><div>I suppose you could say that nested <i>types</i> are different from nested <i>functions,</i> but then we start getting complexity in a different direction. And it still doesn&#39;t fix the default access within a private type.</div></div></blockquote><div><br></div><div>Let me offer a principled rule: if I write `private var foo`, then `foo` is invisible at such places within the declaration where writing `private var bar` at the same place would cause `bar` to be visible where `foo` is not or vice versa.</div></div></div></div></div></blockquote><br></div></span><div>I’m sorry, I don’t understand. </div><div><br></div><div>Stepping back, though, this part of the proposal <i>was</i> discussed back when it was first going through, and it was settled (after some disagreement and discussion) that pure lexical scoping was the best choice.</div></div></blockquote><div><br></div><div>I entirely misunderstood that part of the debate. I had thought the gist of the discussion was that SE-0025 itself was an explicit break from purely lexical scoping, that the proponents of pure lexical scoping were arguing against its adoption, and that its acceptance by the core team was a move away from purely lexical scoping.</div><div><br></div><div>Let me see if I can rephrase the difficulty as I perceive it. I had thought that this was an equivalent formulation of the problem that you are addressing with the amendment. The interpretation of `private` as a purely lexical scope results in the scenario as follows:</div><div><br></div><div>1. I declare `private var foo`</div><div>2. There are places in code where `foo` is visible but where its access level cannot be uttered (e.g., within a nested type, `foo` is not private to that nested type, but it is more narrow in scope than fileprivate, internal, or public)</div><div><br></div><div>Your proposal is to allow `fileprivate` to be used in place of the unutterable access level. This seems like a hack. The necessity for it would go away if we stipulated `private` to exclude all places in code where `foo` is visible but where its access level cannot be uttered.</div></div></div></div></div></blockquote><div><br></div></div></div>You have this wrong.  It is not that you declare `private var foo` and then in specific places it is visible but you can’t utter its access control.  </div><div><br></div><div>The problem is when you use `private` on any construct which introduces a scope that contains further declarations.  You cannot utter the default access control for the members of that scope.  Here are examples:</div><div><br></div><div>private struct S {</div><div>    var foo: Int</div><div>}</div><div><span class=""><div>private class C {</div><div>    var foo: Int</div><div>}</div></span><div><div>private enum E {</div><div>    var foo: Int { return 42 }</div><div>}</div><div>private extension S {</div><div>    func bar() {}</div><div>}</div></div></div><div> </div><div>In all of these examples `foo` and `bar` are visible within the top level scope, but not outside the file.</div></div></blockquote><div><br></div><div>Sorry, yes, that is one problem. The related problem I was trying to describe was this:</div><div><br></div><div>```</div><div>public struct A {</div><div>  private var foo: Int</div><div>  internal struct B {</div><div>    // I cannot utter the access control for `foo` here</div><div>    // and there is nothing I can declare here to be visible</div><div>    // exactly where `foo` is visible</div><div>  }</div><div>}</div><div>```</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>In this case that happens to correspond to `fileprivate` which is probably why Jordan selected that keyword.  In cases where these are not top level declarations, but nested within a scope these will be visible within that scope, but not at the top level of the file.  In *no* case does the unutterable access level correspond to *internal* which is probably why Jordan did not suggest using that.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-Matthew</div></font></span><span class=""><div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span><font color="#888888"><div><br></div><div>Jordan</div><br></font></span></div></blockquote></div><br></div></div>
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></span></div></blockquote></div><br></div></div>