Swift 2: Dictionary extension thinks subscript ambiguous
| Originator: | DaNmarner | ||
| Number: | rdar://22774760 | Date Originated: | 20-Sep-2015 01:23 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 7.0 (7A218) |
| Classification: | Other Bug | Reproducible: | Always |
Summary:
In the following code, Xcode complains that there are four candidate, while it’s not ambiguous at all:
import Foundation
enum DrillingError: ErrorType {
case BadKey
case NotAContainer
case KeyMissing
}
extension Dictionary {
func drill(keys: [Key]) throws -> AnyObject {
guard !keys.isEmpty else {
throw DrillingError.KeyMissing
}
if let childDictionary = self[keys.first!] as? Dictionary {
do {
try childDictionary.drill(Array(keys.dropFirst()))
} catch let error {
throw error
}
} else {
if let childArray = self[keys.first!] as? Array { // <— Xcode complains that this subscript is ambiguous
}
}
}
func drill(keys: Key ...) throws -> AnyObject {
do {
return try drill(keys)
} catch let error {
throw error
}
}
}
Steps to Reproduce:
Try compile the code above in Xcode project or Playground
Expected Results:
The compiler should proceed to find more legit errors.
Actual Results:
The complier reports an error that’s bogus.
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!