[swift-evolution] [Pitch] Fully eliminate implicit bridging conversions in Swift 3

Joe Pamer jpamer at apple.com
Tue Apr 19 12:17:51 CDT 2016


> On Apr 19, 2016, at 7:28 AM, Greg Parker <gparker at apple.com> wrote:
> 
> 
>> On Apr 18, 2016, at 8:21 PM, Joe Pamer via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> I propose that we fully eliminate implicit bridging conversions in Swift 3. This would mean that some users might have to introduce introduce a few more ‘as’ casts in their code, but we would remove another special case from Swift's type system  and be able to further simplify the compiler. If anyone is curious and would like to take this model for a spin, I’ve pushed an experimental branch that implements this proposed change, inhibit-implicit-conversions.
> 
> What happens with string literals? Are they implicitly converted to NSString as necessary?

Sort of - yes. The types of literal expressions are always inferred from context, so for string literals they will be inferred as NSString or String as necessary. 

> Which of the following will be legal?
> 
>     import Foundation
>     func s(_ str: String) { }
>     func ns(_ str: NSString) { }
> 
>     let str: String = "foo"
>     let nsstr: NSString = "foo"
> 
>     NSLog("foo”)

legal

>     NSLog(str)

legal - the NSLog initializer is imported as having type func NSLog(_ format: String, _ args: CVarArg...)

>     NSLog(nstr)

illegal, per the imported initializer declaration above

> 
>     s("foo”)

legal

>     s(str)

legal

>     s(nsstr)

illegal

> 
>     ns("foo”)

legal

>     ns(str)

illegal

>     ns(nsstr)

legal

Thanks,
- Joe

> 
> -- 
> Greg Parker     gparker at apple.com <mailto:gparker at apple.com>     Runtime Wrangler
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160419/51e970c9/attachment.html>


More information about the swift-evolution mailing list