Swift 3: Erroneous warning when casting NSMutableSet to Swift Set

Originator:wetzeal
Number:rdar://29443360 Date Originated:30-Nov-2016
Status:Open Resolved:
Product:Developer Tools Product Version:
Classification: Reproducible:Always
 
Summary:
Casting an NSMutableSet to a Swift Set<AnyHashable> generates the warning “Cast from ’NSMutableSet’ to unrelated type ‘Set<AnyHashable>’ always fails”, however the cast succeeds.

Steps to Reproduce:
Paste this code into a playground:

import UIKit
let stuff: NSMutableSet = ["a", "q", "fourteen"]
let q = stuff as? Set<AnyHashable>

Expected Results:
No warning is generated, as NSMutableSet can be cast just like an NSSet

Actual Results:
A warning is shown which contradicts the cast’s visible success

Regression:
This seems to have been introduced with the new automatic Foundation to Swift Stdlib conversion in Swift 3

Notes:
This warning does not happen for an NSSet, only NSMutableSet. See attached playground for an example. This occurs in stable Xcode 8.1 as well as Xcode 8.2 beta (8C30a)

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!