<div dir="ltr">&gt; What do you imagine being inside .complicatedStuff()? It shouldn&#39;t be possible for it to change foo to nil, as even if .complicatedStuff() reassigned this, it would be doing so as type T.<br><div><br></div><div>Why do you think so? All objects can be changed in any method. Let&#39;s rename foo to pet and complicatedStuff to setFree to give a specific example:</div><div><br></div><div><div>class Pet {</div><div>    var owner: Person?</div><div>    func setFree() </div><div>    {</div><div>       // Maintain the relationship correctness.</div><div>        owner?.pet = nil</div><div>        owner = nil</div><div>    }</div><div>}</div><div><br></div><div>class Person { </div><div><br></div><div>var pet: Pet? </div><div><br></div><div>func ... {</div><div>  if pet != nil {</div><div>    pet.setFree() // this sets pet = nil</div><div>    pet.setFree() // ???? what does this do ????</div><div>    pet.setFree()</div><div>  }</div><div>}</div></div><div>}</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Nov 9, 2016 at 10:51 AM Haravikk &lt;<a href="mailto:swift-evolution@haravikk.me">swift-evolution@haravikk.me</a>&gt; wrote:<br></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" class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On 8 Nov 2016, at 12:22, ilya &lt;<a href="mailto:ilya.nikokoshev@gmail.com" class="gmail_msg" target="_blank">ilya.nikokoshev@gmail.com</a>&gt; wrote:</div><div class="gmail_msg"><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">(1) You can define different methods with the same name on T and Optional&lt;T&gt; (description is such an example). Then what does this do?<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">// someMethod is defined both for T and T?</div><div class="gmail_msg">// var foo: T?</div><div class="gmail_msg">if foo != nil {</div><div class="gmail_msg">    foo.someMethod()</div><div class="gmail_msg">}</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I say there is a clear expectation that foo.someMethod() should call the method of T?, even inside the if block, since this is how the dot works. However, according to the proposal it will call another method (or become an error?).<br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div class="gmail_msg">I think the languages that use optional narrowing are the ones where T? is not a separate type, so that it cannot have its own methods.</div></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg">Hmm, that is definitely a wrinkle in the plan; it&#39;s very much an edge case (someone defining something on optionals that they probably shouldn&#39;t) but not an easy one to resolve. I suppose I&#39;ll have to amend the proposal to suggest type widening in that case, such that you would need to use ! or ? as normal to specify the unwrapped value. The tricky part is that it means the value would have to be widened from the start, otherwise you&#39;d be accessing the value in two different ways in the same block of code, which would mean that narrowing would need to be blocked if there&#39;s an incompatible statement further down… ugh, perhaps a keyword will be necessary then? I was really hoping to avoid having to add one though.</div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div dir="ltr" class="gmail_msg"><div class="gmail_msg">(2) Should this work?</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">// compilcatedStuff is a method of T</div><div class="gmail_msg"><div class="gmail_msg">// class A { var foo: T? }</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">if foo != nil {</div><div class="gmail_msg">    foo.compilcatedStuff()</div><div class="gmail_msg">    foo.compilcatedStuff()</div><div class="gmail_msg"><div class="gmail_msg">    foo.compilcatedStuff()</div><div class="gmail_msg">}<br class="gmail_msg"></div></div><div class="gmail_msg"><br class="gmail_msg"></div></div><div class="gmail_msg">Suppose the compiler doesn&#39;t have enough information about compilcatedStuff to know what happens inside. Then it&#39;s possible that foo.compilcatedStuff will actually change foo (for example, foo could be a relationship and compilcatedStuff may be deleting the relationship). So, what is the suggestion for this example? Perhaps</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg">if foo != nil {</div><div class="gmail_msg">    foo.compilcatedStuff()</div><div class="gmail_msg">    foo?.compilcatedStuff()</div><div class="gmail_msg">    foo?.compilcatedStuff()</div><div class="gmail_msg">}</div><div class="gmail_msg"><br class="gmail_msg"></div></div><div class="gmail_msg">or some other choice?</div></div></blockquote></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"></div><br class="gmail_msg"><div class="gmail_msg">What do you imagine being inside .complicatedStuff()? It shouldn&#39;t be possible for it to change foo to nil, as even if .complicatedStuff() reassigned this, it would be doing so as type T.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"></div><blockquote type="cite" class="gmail_msg"></blockquote></blockquote><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On 9 Nov 2016, at 06:51, David Hart &lt;<a href="mailto:david@hartbit.com" class="gmail_msg" target="_blank">david@hartbit.com</a>&gt; wrote:</div></blockquote></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><div style="word-wrap:break-word" class="gmail_msg"><blockquote type="cite" class="gmail_msg"><blockquote type="cite" class="gmail_msg">On 3 Nov 2016, at 20:23, Nevin Brackett-Rozinsky via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br class="gmail_msg"></blockquote></blockquote><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><blockquote type="cite" class="gmail_msg"><br class="m_824360450323016294Apple-interchange-newline gmail_msg"></blockquote><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><span style="font-size:14px;float:none;display:inline!important" class="gmail_msg">This looks like a lot of complexity for very little gain.</span></blockquote><div style="font-size:14px" class="gmail_msg"><blockquote type="cite" class="gmail_msg"><br class="gmail_msg"></blockquote></div><div style="font-size:14px" class="gmail_msg"><blockquote type="cite" class="gmail_msg">Aside from any implementation concerns, this proposal substantially increases the cognitive load on developers. To figure out what a piece of code means, someone reading it will have to mentally keep track of a “type stack” for every variable. That is the opposite of “clarity at the point of use”.</blockquote></div></div></blockquote></div><blockquote type="cite" class="gmail_msg"><br class="gmail_msg"></blockquote><div class="gmail_msg"><blockquote type="cite" class="gmail_msg">Very well said. I think this is perhaps the number one complaint I have about the proposal.</blockquote></div><div class="gmail_msg"><br class="gmail_msg"></div></div></div></div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg">Did you see my response to this? There should be no particular cognitive load increase; think of the feature like type inference, the idea here is that the type-checker is gaining the same knowledge that you already have, i.e- you know something isn&#39;t nil, so the type-checker should too.</div></div></div></div></div></blockquote></div>