<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 26, 2016, at 11:26, Chris Lattner via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Apr 26, 2016, at 12:15 AM, Aleksandar Petrovic via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div id="bloop_customfont" class="" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;">Hi Swift community, I have a question.</div><div id="bloop_customfont" class="" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;"><br class=""></div><div id="bloop_customfont" class="" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;">This is a valid Swift code:</div><div id="bloop_customfont" class="" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;"><br class=""></div><div id="bloop_customfont" class="" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;"><div id="bloop_customfont" class="" style="margin: 0px;">func testFunc(times: Int, fn: ((Int)-&gt;Void)? = nil) {</div><div id="bloop_customfont" class="" style="margin: 0px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>guard let f = fn else { return }</div><div id="bloop_customfont" class="" style="margin: 0px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>for i in 1 ..&lt; times {</div><div id="bloop_customfont" class="" style="margin: 0px;"><span class="Apple-tab-span" style="white-space: pre;">                </span>f(i)</div><div id="bloop_customfont" class="" style="margin: 0px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div id="bloop_customfont" class="" style="margin: 0px;">}</div><div id="bloop_customfont" class="" style="margin: 0px;"><br class=""></div><div id="bloop_customfont" class="" style="margin: 0px;">And this is not:</div><div id="bloop_customfont" class="" style="margin: 0px;"><br class=""></div><div id="bloop_customfont" class="" style="margin: 0px;"><div id="bloop_customfont" class="" style="margin: 0px;">func testFunc(times: Int, @noescape fn: ((Int)-&gt;Void)? = nil) {</div><div id="bloop_customfont" class="" style="margin: 0px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>guard let f = fn else { return }</div><div id="bloop_customfont" class="" style="margin: 0px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>for i in 1 ..&lt; times {</div><div id="bloop_customfont" class="" style="margin: 0px;"><span class="Apple-tab-span" style="white-space: pre;">                </span>f(i)</div><div id="bloop_customfont" class="" style="margin: 0px;"><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div id="bloop_customfont" class="" style="margin: 0px;">}</div><div class=""><br class=""></div><div class="">I can't think of any hard reason why the @noescape parameter of the function can't be nullable (and, with default value, be optional), but maybe I'm missing something. Is there any plan to correct this in 3.0?</div></div></div></div></blockquote><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">There are two ways to fix this: a horrible hack that special cases optionals, or the more principled solution that treats optional as the underlying enum type that it is, and making @noescape propagate through to the members of the .some case.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">You can probably guess this, but I’d prefer to discuss fixing the full generality of the problem, not providing a special case in the compiler for this.</div></div></blockquote><br class=""></div><div>Making @noescape work for an arbitrary type doesn’t make sense because we don’t know what that type uses its generic parameter for. The reason we can do it for Optional is because Optional is essentially just a wrapper around T, and the only reason it’s <i class="">interesting</i>&nbsp;is because we allow an implicit conversion from a closure literal to an optional function type. Anything else would require the closure to explicitly be passed to an initializer or other function to make the types line up, which would clearly not be considered noescape.</div><div><br class=""></div><div>We could consider extending this to all enums, but clearly not all structs. I think it’s perfectly reasonable to do this just for Optional.</div><div><br class=""></div><div>Jordan</div><br class=""></body></html>