[swift-evolution] Proposal: Deprecate optionals in string interpolation

Chris Lattner clattner at apple.com
Sat Jun 18 23:59:22 CDT 2016


> On Jun 16, 2016, at 12:44 PM, Charlie Monroe via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Sorry, didn't have time to actually submit the proposal, but it at least gave me some time to think it through a few more times.
> 
> After reconsiderations, I suggest the following:
> 
> - deprecation of interpolation of optionals.
> - extending the Optional type by:
> 	- var detailedDescription: String - which will return the same value as until now: "nil" for nil and "Optional(value)" for .some(_). This is due to .description and .debugDescription's documentation discouraging direct invocation.
> 
> 	- func descriptionWithDefaultValue(_ defaultValue: String = "nil") -> String - which would return either the description of the value, or `defaultValue`.
> 
> So, when the compiler runs into interpolation of an Optional, it issues a warning with a fix-it, that by default calls .descriptionWithDefaultValue() on the optional.

I think that this is overcomplicating the issue.  I’d suggest that someone just implement a simple compiler patch (which doesn’t need an evolution proposal):

1. Produce a warning when a string interpolation includes a non-redundantly-parenthesized optional, saying that this is probably a bug.
2. Attach two notes (with fixits) to the warning:
2a. a note that adds redundant parens around the parameter, silencing the warning.
2b. a note that fixits the issue with a “!” or "?? <#placeholder#>"

I agree that this should be fixed.

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160618/1f541bf7/attachment.html>


More information about the swift-evolution mailing list