<div dir="ltr">@Jordan,<div><br></div><div>You said &quot;<span style="font-size:12.8px">I don&#39;t think we want to change or overload that rule to also look up static members of the </span><i style="font-size:12.8px">enclosing lexical context type</i><span style="font-size:12.8px"> (i.e. the type of &#39;self&#39;).&quot; </span>But you do already; inside an enum, e.g.:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">enum Enum {<br>    case one<br>    case two<br>    func e() -&gt; String {<br>        if self == .one {<br>            return &quot;one&quot;<br>        } else if self == .two {<br>            return &quot;two&quot;<br>        }<br>        return &quot;unkown&quot;<br>    }<br>}</blockquote><div>


























<p class="">Compared to inside a static:<br></p>
</div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">class Static {<br>    class One: Static {}<br>    static let one = One()<br>    class Two: Static {}<br>    static let two = Two()<br>    func e() -&gt; String {<br>        if self === Static.one {<br>            return &quot;one&quot;<br>        } else if self === Static.two {<br>            return &quot;two&quot;<br>        }<br>        return &quot;unknown&quot;<br>    }<br>}</blockquote><div><p class=""><span class="">Why so different? The enum version looks inside the type `Enum` to find `.one` and `.two`, but the static version doesn&#39;t look inside the type `Static` and hence you have to say `Static.one` and `Static.two` :(</span></p></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">  -- Howard.<br></div></div>
<br><div class="gmail_quote">On 16 February 2016 at 05:40, 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"><div style="word-wrap:break-word"><div><div class="h5"><br><div><blockquote type="cite"><div>On Feb 15, 2016, at 8:58, Erica Sadun via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word"><div>While discussing leading enumeration dot prefixes, Howard Lovatt asked why static properties and methods could not be inferred via a dot prefix as well. Based on Swift-Evolution conventions, here&#39;s a new thread to discuss this idea: specifically, would it be beneficial (and/or possible) to use dot prefixes to denote static member references in instance member code.</div><div><br></div><div>Howard wrote:</div><div><br></div><div></div><blockquote type="cite"><div><span style="font-family:Palatino-Roman">+1 for the proposal, it is wierd to use `.` in some places and not others. </span><div style="font-family:Palatino-Roman"><br></div><div style="font-family:Palatino-Roman">On the subject of static methods and properties in general, would it be possible for `.name` to be a reference to a static and `name` a reference to an instance? EG:</div><div style="font-family:Palatino-Roman"><br></div><div><font face="Menlo">    .name = x // static</font></div><div><font face="Menlo">    name = x // instance</font></div><div><font face="Menlo">    x = name + .name // instance + static</font></div><div><font face="Menlo">    r = name ... .name // instance ... static, needs space</font></div><div><font face="Menlo">    r = name...Type.name // Can still qualify with type name</font></div></div><div style="font-family:Palatino-Roman"><br></div></blockquote><div><br></div><span>Under the current system, you must explicitly name or derive a type to access static members from instance member implementations.</span><div style="font-size:8px"><br style="font-size:8px"></div><div style="font-size:8px"><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">struct</span> MyStruct {</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo">    <span style="color:#bb2ca2">static</span> <span style="color:#bb2ca2">func</span> staticMember() {}</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;min-height:21px">    <br></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo">    <span style="color:#bb2ca2">func</span> instanceMember() {</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)"><span style="color:rgb(0,132,0)">        // name a type</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo">        <span style="color:rgb(79,129,135)">MyStruct</span>.<span style="color:rgb(49,89,93)">staticMember</span>() <span style="color:rgb(0,132,0)">// works</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)"><span style="color:rgb(0,132,0)"><br></span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)"><span style="color:rgb(0,132,0)">        // derive a type</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span>        </span>self<span>.</span>dynamicType<span>.</span><span style="color:#31595d">staticMember</span><span>() </span><span style="color:#008400">// works</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)">        </div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span>        </span>// error: value of tuple type &#39;()&#39; has no member &#39;staticMember&#39;</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span>        </span>// does not work</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo">        .staticMember()</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo">    }</div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo">}</div><div style="font-size:8px"><br style="font-size:8px"></div><div style="font-size:12px">Using dot prefixes for static member access:</div></div><div><br></div><div>* Has precedent in enumeration members</div><div>* Would streamline Swift code</div><div>* Is visually differentiated from `self`-prefixed instance member references</div><div><br></div><div>What are your thoughts, both technical and philosophical, on a change like this? Thanks in advance for your feedback.</div></div></div></blockquote><br></div></div></div><div>Dot-prefixed member expressions are currently looked up as static members of the<i> contextual type,</i> which lets you do things like this:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>import AppKit</div><div>let colors: [NSColor] = [.redColor(), .blueColor()]</div></blockquote><br><div>I don&#39;t think we want to change or overload that rule to also look up static members of the <i>enclosing lexical context type</i> (i.e. the type of &#39;self&#39;).</div><div><br></div><div>Jordan</div></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>