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-4949] No error for using 'as' patterns with CF types #47526

Open
belkadan opened this issue May 19, 2017 · 5 comments
Open

[SR-4949] No error for using 'as' patterns with CF types #47526

belkadan opened this issue May 19, 2017 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers

Comments

@belkadan
Copy link
Contributor

Previous ID SR-4949
Radar rdar://problem/32255478
Original Reporter @belkadan
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug
Assignee None
Priority Medium

md5: 62d9e9e2da2d4b28fa3d10ebd350dba6

Issue Description:

import Foundation

let x = ([1: 2] as NSDictionary) as Any

switch x {
case let b as CFBoolean:
    print("it's a cfbool: \(b)")
    
default:
    print("n/a")
}

We should warn here that we can't actually do checked downcasts for CF types, like we do with as?.

import Foundation
let x = ([1: 2] as NSDictionary) as Any
let y = x as? CFDictionary // error: conditional downcast to CoreFoundation type 'CFDictionary' will always succeed

We can't make it an error because that would break source compatibility, but at least a warning will work. The best workaround today (and a possible fix-it):

switch x {
case let rawB:
    let b = rawB as! CFBoolean
    print("it's a cfbool: \(b)")
    
default:
    print("n/a")
}
@swift-ci
Copy link
Collaborator

swift-ci commented Jun 9, 2017

Comment by Dmitry Venikov (JIRA)

What warning message should be used?

@belkadan
Copy link
Contributor Author

I think it's okay to reuse the message that as? uses (but as a warning).

@swift-ci
Copy link
Collaborator

Comment by Dmitry Venikov (JIRA)

Finally I'm starting to investigate this issue.

{code:swift}case let b as CFBoolean

@belkadan
Copy link
Contributor Author

Resetting assignee for all Starter Bugs not modified since 2018.

@theblixguy
Copy link
Collaborator

I think the runtime should support this by calling CFGetTypeID and then performing a cast... or maybe we can insert an implicit check instead.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants