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

Chris Lattner clattner at apple.com
Mon May 23 18:23:39 CDT 2016


> On May 23, 2016, at 12:12 PM, Charlie Monroe via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> If the URL path property was defined not to return ‘String?' but to return ‘Any’ (which can of course hold an Optional just like it can hold any other type) what would the proposed compiler behavior be?
> 
> No warning. Since you cast Optional to Any, no warning can even be issued since that will eventually be determined during runtime, there's not much the compiler can do here.

I agree.  It is important for optionals to be string literal convertible in generic situations as well as when boxed in an existential like Any.  That said, emitting a warning when the compiler knows statically that it has an optional makes a lot of sense.

-Chris


More information about the swift-evolution mailing list