<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 Jan 12, 2018, at 2:00 PM, John McCall 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 12, 2018, at 12:53 PM, BJ Homer 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=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I agree that this behavior is annoying. However, wouldn’t it be source-breaking to change this now?</div></div></blockquote><div class=""><br class=""></div>Source compatibility means that we can't change the behavior of Swift 3 / Swift 4 source. This would be a semantic change when building Swift 5 source (or later). There is no technical reason we couldn't make this change. It does need to meet a very high bar, because we are trying to avoid making significant semantic breaks. My personal sense is that it meets that bar because double-optionals can be very confusing for novices and very annoying for everyone else.</div><div class=""><br class=""></div><div class="">I think most use sites probably do want the optional-collapsing behavior. 'try?' is already "sugar" syntax and should aim to be as convenient as possible for the majority of use cases. Much like the collapsing done by optional chaining, I think you can come up with examples where somebody would want the non-collapsing behavior, but it doesn't seem unreasonable to say that they just shouldn't use the sugar.</div></div></div></blockquote><div><br class=""></div><div>I think I agree with this. `try?` already has some implicit optional collapsing behavior when it is used in an expression where there is more than one call that can throw. The most intuitive behavior is for this collapsing to compose with the collapsing of optional chaining.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">John.</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">-BJ<br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Jan 12, 2018, at 10:25 AM, Russ Bishop 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=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Greetings swift-evolution!</div><div class=""><br class=""></div><div class="">There is currently a disconnect between optional chaining and try? when it comes to optional flattening:</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="color: #ba2da2" class="">struct</span> SomeType {</div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""> <span style="color: #ba2da2" class="">func</span> nonThrow() -> <span style="color: #4f8187" class="">SomeType</span>? { <span style="color: #ba2da2" class="">return</span> <span style="color: #ba2da2" class="">self</span> }</div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""> <span style="color: #ba2da2" class="">func</span> doThrow() <span style="color: #ba2da2" class="">throws</span> -> <span style="color: #4f8187" class="">SomeType</span>? { <span style="color: #ba2da2" class="">return</span> <span style="color: #ba2da2" class="">self</span> }</div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""> <span style="color: #ba2da2" class="">func</span> nonOptional() <span style="color: #ba2da2" class="">throws</span> -> <span style="color: #4f8187" class="">SomeType</span> { <span style="color: #ba2da2" class="">return</span> <span style="color: #ba2da2" class="">self</span> }</div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">}</div><div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(49, 89, 93);" class=""><span style="color: #ba2da2" class="">let</span><span style="" class=""> w = </span><span style="color: #4f8187" class="">SomeType</span><span style="" class="">().</span>nonThrow<span style="" class="">()?.</span>nonThrow<span style="" class="">()?.</span>nonThrow<span style="" class="">()?.</span>nonThrow<span style="" class="">()</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 132, 0);" class="">// w has type SomeType?</div><div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(49, 89, 93);" class=""><span style="color: #ba2da2" class="">let</span><span style="" class=""> x = </span><span style="color: #ba2da2" class="">try</span><span style="" class="">? </span><span style="color: #4f8187" class="">SomeType</span><span style="" class="">().</span>nonOptional<span style="" class="">().</span>nonOptional<span style="" class="">().</span>nonOptional<span style="" class="">().</span>nonOptional<span style="" class="">()</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 132, 0);" class="">// x has type SomeType?</div><div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(49, 89, 93);" class=""><span style="color: #ba2da2" class="">let</span><span style="" class=""> y = </span><span style="color: #ba2da2" class="">try</span><span style="" class="">! </span><span style="color: #4f8187" class="">SomeType</span><span style="" class="">().</span>doThrow<span style="" class="">()?.</span>doThrow<span style="" class="">()?.</span>doThrow<span style="" class="">()?.</span>doThrow<span style="" class="">()</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 132, 0);" class="">// y has type SomeType?</div><div style="margin: 0px; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Helvetica; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(49, 89, 93);" class=""><span style="color: #ba2da2" class="">let</span><span style="" class=""> z = </span><span style="color: #ba2da2" class="">try</span><span style="" class="">? </span><span style="color: #4f8187" class="">SomeType</span><span style="" class="">().</span>doThrow<span style="" class="">()?.</span>doThrow<span style="" class="">()?.</span>doThrow<span style="" class="">()?.</span>doThrow<span style="" class="">()</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 132, 0);" class="">// z has type SomeType??</div></div><div class=""><span style="" class=""><br class=""></span></div></div></div><div class=""><br class=""></div><div class="">We get a double-optional only when combining try? and optional-chaining. That is inconvenient and it would be natural to have the compiler do the flattening here.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">If anyone is interested in working on the proposal or implementation please let me know. It would make a nice self-contained task if you're looking to start contributing.</div><div class=""><br class=""></div><br class=""><div class="">
Russ Bishop<br class=""> Simulator<br class=""><br class="">
</div>
<br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>