<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Wouldn't this work in Swift 3 though?</div><div id="AppleMailSignature"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div id="AppleMailSignature"><span style="background-color: rgba(255, 255, 255, 0);">func testFunc(times: Int, fn: (@noescape (Int)->Void)? = nil) { … }</span></div><div id="AppleMailSignature"><br>Sent from my iPad</div><div><br>On Apr 26, 2016, at 11:26 AM, Chris Lattner via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 26, 2016, at 12:15 AM, Aleksandar Petrovic via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: 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;" class="">Hi Swift community, I have a question.</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: 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;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: 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;" class="">This is a valid Swift code:</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: 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;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: 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;" class=""><div id="bloop_customfont" style="margin: 0px;" class="">func testFunc(times: Int, fn: ((Int)->Void)? = nil) {</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>guard let f = fn else { return }</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>for i in 1 ..< times {</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>f(i)</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div id="bloop_customfont" style="margin: 0px;" class="">}</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">And this is not:</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class=""><div id="bloop_customfont" style="margin: 0px;" class="">func testFunc(times: Int, @noescape fn: ((Int)->Void)? = nil) {</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>guard let f = fn else { return }</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>for i in 1 ..< times {</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>f(i)</div><div id="bloop_customfont" style="margin: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div id="bloop_customfont" style="margin: 0px;" class="">}</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>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><br class=""></div><div>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><br class=""></div><div>-Chris</div><br class=""></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>