Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-8414] Implicit bridge-crossing to Cocoa protocols #50939

Closed
mattneub opened this issue Jul 30, 2018 · 2 comments
Closed

[SR-8414] Implicit bridge-crossing to Cocoa protocols #50939

mattneub opened this issue Jul 30, 2018 · 2 comments
Labels
compiler The Swift compiler in itself improvement type checker Area → compiler: Semantic analysis

Comments

@mattneub
Copy link

Previous ID SR-8414
Radar None
Original Reporter @mattneub
Type Improvement
Status Closed
Resolution Won't Do
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, TypeChecker
Assignee None
Priority Medium

md5: d03a46d5fbe7739dbe5b2c9320149b4e

Issue Description:

I wonder whether this sort of thing could be made to compile?

let sc : NSSecureCoding =  "howdy"
let c : NSCoding = 1

The compiler could reason: Well, this protocol is an Objective-C class protocol, so it is analogous to a type AnyObject. If this String/Int were assigned where an AnyObject is expected, I would cross the bridge to NSString / NSNumber. If I do that, do I get an NSSecureCoding / NSCoding adopter? Yes!

As it is, I have to say `as NSString`, `as NSNumber`, which is surprising considering how we usually cross the bridge from Swift implicitly without a murmur.

The issue arises in real life particularly because a number of Cocoa APIs do specify an NSSecureCoding parameter, but the programmer typically does not know that, passes a String or an Int, and is surprised when that doesn't work.

@belkadan
Copy link
Contributor

cc @DougGregor, @rudkx

@DougGregor
Copy link
Member

Implicit conversions from value types to reference types were present in Swift < 3. SE-0072 eliminated these implicit conversions, which included the implicit conversion requested here. While prior decisions can be revisited via the Swift evolution process (go to forums.swift.org for such discussions), I don't think there is any chance that the Swift Core Team would accept re-introducing these implicit conversions.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself improvement type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants