swiftlang/swift
GitHub で見る[SR-4949] No error for using 'as' patterns with CF types
Open
#47,526 opened on 2017年5月19日
bugcompilerdiagnostics qualitygood first issue
説明
| Previous ID | SR-4949 |
| Radar | rdar://problem/32255478 |
| Original Reporter | @belkadan |
| Type | Bug |
| 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")
}