<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 Oct 3, 2016, at 8:49 PM, Kevin Ballard 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="">


<title class=""></title>

<div class=""><div class="">I assume you meant that as a reply to me?<br class=""></div>
<div class=""><br class=""></div>
<div class="">The problem is twofold:<br class=""></div>
<div class=""><br class=""></div>
<div class="">1. Printing the value without adornment, or "nil" for nil, is a very common thing to want to do and we shouldn't have to write code like `\(x.map(String.init(describing:)) ?? "nil")` to accomplish it.<br class=""></div></div></div></blockquote><div><br class=""></div><div>My point is before you were unable to do this without the ‘uglyness’ presented here anyway [you would have gotten “Optional(“value”)”], so I don’t see the point of raising this concern. &nbsp;If you want the old behavior, just ask for it with an explicit cast or `.debugDescription`.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">
<div class="">2. Due to the changes made to IUOs, if you use a IUO in a string interpolation, previously it would print as desired (either the value or the string `"nil"`) but now it prints as Optional (e.g. with the `"Optional(…)"` wrapper).<br class=""></div></div></div></blockquote><div><br class=""></div><div>IUOs are not in the scope for this proposal, but I get your point.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">
<div class=""><br class=""></div>
<div class="">-Kevin</div>
<div class=""><br class=""></div>
<div class="">On Mon, Oct 3, 2016, at 05:43 PM, Robert Widmann via swift-evolution wrote:<br class=""></div>
<blockquote type="cite" class=""><div class=""><div style="direction:inherit;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Under our proposal you can return to the old semantics of printing nil with an explicit optional cast - one which we will offer to insert for you.</span><br class=""></div>
<div style="direction:inherit;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"></span><br class=""></div>
<div style="direction:inherit;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Otherwise if you actually intend for a default value that value would have type Int, not String. &nbsp;Under the current regime if you want to print something custom the for nil the way you've got it now you're going to have to go through the reflecting initializer anyway so I don't see a problem here.</span><br class=""></div>
<div style="direction:inherit;" class=""><br class=""></div>
<div class="">~Robert Widmann<br class=""></div>
</div>
<div class=""><div class=""><br class=""></div>
<div class="">2016/10/03 19:25、Charlie Monroe via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; のメッセージ:<br class=""></div>
</div>
<blockquote type="cite" class=""><div class=""><div class="">I've already suggested this quite some time back and was told that this doesn't need to go through evolution. It's filed here:&nbsp;<a href="https://bugs.swift.org/browse/SR-1882" class="">https://bugs.swift.org/browse/SR-1882</a><br class=""></div>
<div class=""><br class=""></div>
<div class="">Unfortunately, I haven't had time to look into it myself and I'm unlikely to have the time anytime soon...<br class=""></div>
<div class=""><div class=""><br class=""></div>
<div class=""><blockquote type="cite" class=""><div class="">On Oct 3, 2016, at 7:52 PM, Harlan Haskins via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div>
<div class=""><br class=""></div>
<div class=""><div class=""><div class=""><span class=""></span><br class=""></div>
<div class=""><div class="">Hey all,<br class=""></div>
<div class=""><br class=""></div>
<div class="">Julio Carrettoni, Robert Widmann, and I have been working on a proposal to mitigate something that's burned us all since Swift 1. We'd love some feedback!<br class=""></div>
<div class=""><br class=""></div>
<div class="">It's available here:&nbsp;<a href="https://gist.github.com/harlanhaskins/63b7343e7fe4e5f4c6cfbe9413a98fdd" class="">https://gist.github.com/harlanhaskins/63b7343e7fe4e5f4c6cfbe9413a98fdd</a><br class=""></div>
<div class=""><br class=""></div>
<div class="">I've posted the current draft below.<br class=""></div>
<div class=""><br class=""></div>
<div class="">Thanks,<br class=""></div>
<div class="">Harlan Haskins<br class=""></div>
<div class=""><br class=""></div>
<div class=""><h1 style="margin-right:0px;margin-bottom:16px;margin-left:0px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238, 238, 238);margin-top:0px !important;" class=""><span class="size" style="font-size: 12px;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Disallow Optionals in String Interpolation Segments</span></span><br class=""></h1><ul style="padding-left:2em;margin-top:0px;margin-bottom:16px;" class=""><li style="" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Proposal:&nbsp;<a style="-webkit-text-decoration-skip:objects;text-decoration:none;" href="https://gist.github.com/harlanhaskins/NNNN-filename.md" class="">SE-NNNN</a></span><br class=""></li><li style="margin-top:0.25em;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Authors:&nbsp;<a style="-webkit-text-decoration-skip:objects;text-decoration:none;" href="https://github.com/harlanhaskins" class="">Harlan Haskins</a>,&nbsp;<a style="-webkit-text-decoration-skip:objects;text-decoration:none;" href="https://github.com/Julioacarrettoni" class="">Julio Carrettoni</a>,&nbsp;<a style="-webkit-text-decoration-skip:objects;text-decoration:none;" href="https://github.com/CodaFi" class="">Robert Widmann</a></span><br class=""></li><li style="margin-top:0.25em;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Review Manager: TBD</span><br class=""></li><li style="margin-top:0.25em;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Status:&nbsp;<span style="font-weight:600;" class="">Awaiting revie</span></span><br class=""></li></ul><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238, 238, 238);" class=""><a style="-webkit-text-decoration-skip:objects;text-decoration:none;float:left;padding-right:4px;line-height:1;" href="https://gist.github.com/harlanhaskins/63b7343e7fe4e5f4c6cfbe9413a98fdd#introduction" class=""><span class="size" style="font-size: 12px;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"></span></span></a><span class="size" style="font-size: 12px;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Introduction</span></span><br class=""></h2><p style="margin-top:0px;margin-bottom:16px;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Swift developers frequently use string interpolation as a convenient, concise syntax for interweaving variable values with strings. The interpolation machinery, however, has surprising behavior in one specific case:&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">Optional&lt;T&gt;</code>. If a user puts an optional value into a string interpolation segment, it will insert either&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">"Optional("value")"</code>&nbsp;or&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">"nil"</code>&nbsp;in the resulting string. Neither of these is particularly desirable, so we propose a warning and fix-it to surface solutions to these potential mistakes.</span><br class=""></p><p style="margin-top:0px;margin-bottom:16px;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Swift-evolution thread:&nbsp;<a style="-webkit-text-decoration-skip:objects;text-decoration:none;" href="https://lists.swift.org/pipermail/swift-evolution/" class="">Discussion thread topic for that proposal</a></span><br class=""></p><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238, 238, 238);" class=""><a style="-webkit-text-decoration-skip:objects;text-decoration:none;float:left;padding-right:4px;line-height:1;" href="https://gist.github.com/harlanhaskins/63b7343e7fe4e5f4c6cfbe9413a98fdd#motivation" class=""><span class="size" style="font-size: 12px;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"></span></span></a><span class="size" style="font-size: 12px;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Motivation</span></span><br class=""></h2><p style="margin-top:0px;margin-bottom:16px;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"><i class="">The Swift Programming Language</i>&nbsp;defines string interpolation segments as "a way to construct a new String value from a mix of constants, variables, literals, and expressions". There is one type that runs counter to this definition:&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">Optional</code>. The&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">.none</code>&nbsp;case in particular is used to indicate the absence of a value. Moreover, its inclusion in interpolation segments leads to the dreaded&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">"nil"</code>&nbsp;in output that is often fed to UI elements. Even barring that, interpolating a non-nil optional value yields&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">"Optional("value")"</code>, a result that is not useful even in logged output.</span><br class=""></p><p style="margin-top:0px;margin-bottom:16px;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Given that the&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">Optional</code>&nbsp;type is never fit for display to the end user, and can often be a surprising find in the console, we propose that requesting an&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">Optional</code>'s debug description be an explicit act. This proposal now requires a warning when using an expression of&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">Optional</code>&nbsp;type within a string interpolation segment.</span><br class=""></p><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238, 238, 238);" class=""><a style="-webkit-text-decoration-skip:objects;text-decoration:none;float:left;padding-right:4px;line-height:1;" href="https://gist.github.com/harlanhaskins/63b7343e7fe4e5f4c6cfbe9413a98fdd#proposed-solution" class=""><span class="size" style="font-size: 12px;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"></span></span></a><span class="size" style="font-size: 12px;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Proposed solution</span></span><br class=""></h2><p style="margin-top:0px;margin-bottom:16px;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">The user will be warned after attempting to use an expression with type&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">Optional&lt;T&gt;</code>&nbsp;in a string interpolation segment. They will then be offered a fixit suggesting they explicitly request the&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">debugDescription</code>&nbsp;of the&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">Optional</code>&nbsp;value instead.</span><br class=""></p><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238, 238, 238);" class=""><a style="-webkit-text-decoration-skip:objects;text-decoration:none;float:left;padding-right:4px;line-height:1;" href="https://gist.github.com/harlanhaskins/63b7343e7fe4e5f4c6cfbe9413a98fdd#detailed-design" class=""><span class="size" style="font-size: 12px;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"></span></span></a><span class="size" style="font-size: 12px;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Detailed design</span></span><br class=""></h2><p style="margin-top:0px;margin-bottom:16px;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Semantic analysis currently does not do much but guarantee the well-formedness of expressions in interpolation segments. These are then fed directly to&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">String.init(stringInterpolationSegment:)</code>&nbsp;and are run through the runtime reflection system to generate a description. Semantic analysis will be tweaked to inspect the result of solving an interpolation segment for an&nbsp;<code style="padding-top:0.2em;padding-right:0px;padding-bottom:0.2em;padding-left:0px;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;" class="">Optional</code>&nbsp;and will offer a fixit in that case.</span><br class=""></p><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238, 238, 238);" class=""><a style="-webkit-text-decoration-skip:objects;text-decoration:none;float:left;padding-right:4px;line-height:1;" href="https://gist.github.com/harlanhaskins/63b7343e7fe4e5f4c6cfbe9413a98fdd#impact-on-existing-code" class=""><span class="size" style="font-size: 12px;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"></span></span></a><span class="size" style="font-size: 12px;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Impact on existing code</span></span><br class=""></h2><p style="margin-top:0px;margin-bottom:16px;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">As this is a warning, code written before this proposal will continue to compile and run with the same semantics as before. Authors of code that makes use of this unsafe pattern will be offered a migration path to the safer, more explicit form.</span><br class=""></p><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238, 238, 238);" class=""><a style="-webkit-text-decoration-skip:objects;text-decoration:none;float:left;padding-right:4px;line-height:1;" href="https://gist.github.com/harlanhaskins/63b7343e7fe4e5f4c6cfbe9413a98fdd#alternatives-considered" class=""><span class="size" style="font-size: 12px;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"></span></span></a><span class="size" style="font-size: 12px;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Alternatives considered</span></span><br class=""></h2><ul style="padding-left:2em;margin-top:0px;margin-bottom:0px !important;" class=""><li style="" class=""><p style="margin-top:16px;margin-bottom:16px;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">A fixit that suggests a default value be inserted would be entirely appropriate (following the style of the fixit introduced in&nbsp;<a style="-webkit-text-decoration-skip:objects;text-decoration:none;" href="https://github.com/apple/swift-evolution/blob/master/proposals/0140-bridge-optional-to-nsnull.md" class="">SE-0140</a>).</span><br class=""></p></li><li style="margin-top:0.25em;" class=""><p style="margin-top:16px;margin-bottom:16px;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Forbidding this pattern by hard error would make this proposal a breaking change that is out of scope for this stage of Swift's development.</span><br class=""></p></li><li style="margin-top:0.25em;" class=""><p style="margin-top:16px;margin-bottom:16px;" class=""><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">A fixit that introduces a force-unwrapping would technically work as well, however it would be fixing a dangerous operation with yet another dangerous operation.</span><br class=""></p></li></ul></div>
</div>
<div class=""><div class=""><br class=""></div>
<div class=""><br class=""></div>
<div class="">Sent from my iPad<br class=""></div>
</div>
</div>
<div class="">_______________________________________________<br class=""></div>
<div class="">swift-evolution mailing list<br class=""></div>
<div class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""></div>
<div class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div>
</div>
</blockquote></div>
</div>
</div>
</blockquote><blockquote type="cite" class=""><div class=""><div class=""><span class="">_______________________________________________</span><br class=""></div>
<div class=""><span class="">swift-evolution mailing list</span><br class=""></div>
<div class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""></div>
<div class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div>
</div>
</blockquote><div class=""><u class="">_______________________________________________</u><br class=""></div>
<div class="">swift-evolution mailing list<br class=""></div>
<div class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""></div>
<div 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 class=""><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="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>