Adding ObjC generic constraint breaks "is"
| Originator: | robnapier | ||
| Number: | rdar://22218124 | Date Originated: | 10-Aug-2015 04:51 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Swift 7b5 |
| Classification: | Other Bug | Reproducible: | Not Applicable |
In the following code, adding the “NSObject” type constraint causes all “is T” checks to return true. This appears to be true of any ObjC type constraint. A type constraint of AnyObject does not cause this problem.
import UIKit
let vc1 = UIViewController()
func istypeGood<T>(check: AnyObject, kindOf: T.Type) -> (Bool) {
return check is T
}
func istypeBad<T: NSObject>(check: AnyObject, kindOf: T.Type) -> (Bool) {
return check is T
}
istypeGood(vc1, kindOf: UIView.self) // false, correct
istypeGood(vc1, kindOf: UIViewController.self) // true, correct
istypeBad(vc1, kindOf: UIView.self) // true, incorrect <======
istypeBad(vc1, kindOf: UIViewController.self) // true, correct
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!