<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>I assume you meant that as a reply to me?<br></div>
<div><br></div>
<div>The problem is twofold:<br></div>
<div><br></div>
<div>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></div>
<div>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></div>
<div><br></div>
<div>-Kevin</div>
<div><br></div>
<div>On Mon, Oct 3, 2016, at 05:43 PM, Robert Widmann via swift-evolution wrote:<br></div>
<blockquote type="cite"><div><div style="direction:inherit;"><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></div>
<div style="direction:inherit;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"></span><br></div>
<div style="direction:inherit;"><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></div>
<div style="direction:inherit;"><br></div>
<div>~Robert Widmann<br></div>
</div>
<div><div><br></div>
<div>2016/10/03 19:25、Charlie Monroe via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; のメッセージ:<br></div>
</div>
<blockquote type="cite"><div><div>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">https://bugs.swift.org/browse/SR-1882</a><br></div>
<div><br></div>
<div>Unfortunately, I haven't had time to look into it myself and I'm unlikely to have the time anytime soon...<br></div>
<div><div><br></div>
<div><blockquote type="cite"><div>On Oct 3, 2016, at 7:52 PM, Harlan Haskins via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div>
<div><br></div>
<div><div><div><span></span><br></div>
<div><div>Hey all,<br></div>
<div><br></div>
<div>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></div>
<div><br></div>
<div>It's available here:&nbsp;<a href="https://gist.github.com/harlanhaskins/63b7343e7fe4e5f4c6cfbe9413a98fdd">https://gist.github.com/harlanhaskins/63b7343e7fe4e5f4c6cfbe9413a98fdd</a><br></div>
<div><br></div>
<div>I've posted the current draft below.<br></div>
<div><br></div>
<div>Thanks,<br></div>
<div>Harlan Haskins<br></div>
<div><br></div>
<div><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;"><span class="size" style="font-size:medium"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Disallow Optionals in String Interpolation Segments</span></span><br></h1><ul style="padding-left:2em;margin-top:0px;margin-bottom:16px;"><li style=""><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">SE-NNNN</a></span><br></li><li style="margin-top:0.25em;"><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">Harlan Haskins</a>,&nbsp;<a style="-webkit-text-decoration-skip:objects;text-decoration:none;" href="https://github.com/Julioacarrettoni">Julio Carrettoni</a>,&nbsp;<a style="-webkit-text-decoration-skip:objects;text-decoration:none;" href="https://github.com/CodaFi">Robert Widmann</a></span><br></li><li style="margin-top:0.25em;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Review Manager: TBD</span><br></li><li style="margin-top:0.25em;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Status:&nbsp;<span style="font-weight:600;">Awaiting revie</span></span><br></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);"><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"><span class="size" style="font-size:medium"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"></span></span></a><span class="size" style="font-size:medium"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Introduction</span></span><br></h2><p style="margin-top:0px;margin-bottom:16px;"><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;">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;">"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;">"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></p><p style="margin-top:0px;margin-bottom:16px;"><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/">Discussion thread topic for that proposal</a></span><br></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);"><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"><span class="size" style="font-size:medium"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"></span></span></a><span class="size" style="font-size:medium"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Motivation</span></span><br></h2><p style="margin-top:0px;margin-bottom:16px;"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"><i>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;">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;">.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;">"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;">"Optional("value")"</code>, a result that is not useful even in logged output.</span><br></p><p style="margin-top:0px;margin-bottom:16px;"><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;">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;">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;">Optional</code>&nbsp;type within a string interpolation segment.</span><br></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);"><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"><span class="size" style="font-size:medium"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"></span></span></a><span class="size" style="font-size:medium"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Proposed solution</span></span><br></h2><p style="margin-top:0px;margin-bottom:16px;"><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;">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;">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;">Optional</code>&nbsp;value instead.</span><br></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);"><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"><span class="size" style="font-size:medium"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"></span></span></a><span class="size" style="font-size:medium"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Detailed design</span></span><br></h2><p style="margin-top:0px;margin-bottom:16px;"><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;">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;">Optional</code>&nbsp;and will offer a fixit in that case.</span><br></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);"><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"><span class="size" style="font-size:medium"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"></span></span></a><span class="size" style="font-size:medium"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Impact on existing code</span></span><br></h2><p style="margin-top:0px;margin-bottom:16px;"><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></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);"><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"><span class="size" style="font-size:medium"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)"></span></span></a><span class="size" style="font-size:medium"><span class="highlight" style="background-color:rgba(255, 255, 255, 0)">Alternatives considered</span></span><br></h2><ul style="padding-left:2em;margin-top:0px;margin-bottom:0px !important;"><li style=""><p style="margin-top:16px;margin-bottom:16px;"><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">SE-0140</a>).</span><br></p></li><li style="margin-top:0.25em;"><p style="margin-top:16px;margin-bottom:16px;"><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></p></li><li style="margin-top:0.25em;"><p style="margin-top:16px;margin-bottom:16px;"><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></p></li></ul></div>
</div>
<div><div><br></div>
<div><br></div>
<div>Sent from my iPad<br></div>
</div>
</div>
<div>_______________________________________________<br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</div>
</blockquote></div>
</div>
</div>
</blockquote><blockquote type="cite"><div><div><span>_______________________________________________</span><br></div>
<div><span>swift-evolution mailing list</span><br></div>
<div><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br></div>
<div><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div>
</div>
</blockquote><div><u>_______________________________________________</u><br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</blockquote><div><br></div>
</body>
</html>