<div dir="ltr"><div class="gmail_extra">On 26 October 2017 at 19:19, Mike Kluev <span dir="ltr"><<a href="mailto:mike.kluev@gmail.com" target="_blank">mike.kluev@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">on Wed, 25 Oct 2017 13:41:40 +0200 David Hart <<a href="mailto:david@hartbit.com" target="_blank">david@hartbit.com</a>> wrote:<div><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
class A {<br>
func foo() {<br>
func local() {<br>
bar() // error: Call to method ‘bar' in function ‘local' requires explicit 'self.' to make capture semantics explicit<br>
}<br>
<br>
// ...<br>
}<br>
}<br></blockquote><div><br></div><div>it's not only about calling "bar"... any variable access will require self. which will be quite annoying, especially given the fact that "local" my not even be used in an escaping context discussed. (*)</div><div><br></div><div>i think it is more consistent to prepend local with self if it is used in an escaping context:</div><div><br></div><div><div>func foo() {</div><div><br></div><div> func local() {</div><div> bar() // no self needed here ever</div><div> variable = 1 // no self needed here, ever</div><div> }</div><div> </div><div> func otherLocal() {</div><div> print("i am not capturing self")</div><div> }</div><div> </div><div> DispatchQueue.main.async {</div><div> local() // error without self</div><div> self.local() // ok</div><div> otherLocal() // ok without self</div><div> }</div><div>}</div></div><div><br></div><div>(*) interestingly, closures always treat themselves as "escaping", even if it's not the case, e.g. even if i only use them in a non-escaping contexts. worth to add an explicit attribute to denote non-escaping closures?</div><div><br></div><div>let closure = @nonescaping {</div><div> print("i am not escaping")</div><div> variable = 1 // ok without self</div><div>}</div><div><br></div><div>DispatchQueue.main.async(<wbr>execute: closure) // error, non escaping closure passed</div><span class="gmail-HOEnZb"><font color="#888888"><div><br></div></font></span></div></div></div></div></blockquote><div><br></div>or, to keep the syntax close to the current one:</div><div class="gmail_quote"><br></div><div class="gmail_quote">let closure = { nonescaping () -> Void in</div><div class="gmail_quote"> print("i am non escaping")</div><div class="gmail_quote"> variable = 1 // ok without self</div><div class="gmail_quote">}</div><div class="gmail_quote"><br></div><div class="gmail_quote">with possible optimisations allowing omitting parameters / return values:</div><div class="gmail_quote"><div class="gmail_quote"><br></div><div class="gmail_quote">let closure = { nonescaping in</div><div class="gmail_quote"> print("i am non escaping")</div><div class="gmail_quote"> variable = 1 // ok without self</div><div class="gmail_quote">}</div><div><br></div></div></div></div>