Xcode 7.2: Swift covariant assignment fails for nested generics
| Originator: | tapikz | ||
| Number: | rdar://24135961 | Date Originated: | 11-Jan-2016 04:26 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 7.2 (7C68) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary: When assigning a more specific generic type to a less specific generic type the compiler throws an error. A simple case is 2 dimensional arrays. The following works just fine let views = Array<UIView>() var objects: Array<NSObject>? objects = views Steps to Reproduce: let views = Array<Array<UIView>>() var objects: Array<Array<NSObject>>? objects = views Expected Results: - Code compiles - The assignment is successful Actual Results: - Cannot assign value of type ‘Array<Array<UIView>>’ to type Array<Array<NSObject>>’ Regression: Unsure if this is a regression Notes: The demonstrated case is the trivial one but the issue is present for all nested generics. ie. let views = Array<Dictionary<String, UIView>>() var objects: Array<Dictionary<String, NSObject>>? objects = views will yield a similar error
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!