Generic extensions in libraries currently broken
| Originator: | thephatmann | ||
| Number: | rdar://20171130 | Date Originated: | 16-Mar-2015 04:54 AM |
| Status: | Duplicate of 16974298 | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.2 |
| Classification: | Reproducible: | Always |
This is a duplicate of rdar://17264362
You cannot currently extend a built-in or standard library generic type with any properties or methods that require the type's generic parameters.
In other words, create a framework project in Swift and add this to a swift file:
extension Dictionary {
func OK() { }
func NotOK(a:KeyType) {
}
}
Now in one of your unit tests, try this (after importing your framework project):
let dict = ["abc": 5, "xyz": 3]
dict.OK()
dict.NotOK("") //oops, linker error
You can use the extension method OK just fine, but as soon as you try to use NotOK, the linker will barf with an Undefined symbols for architecture error. That's because your unit tests are actually a separate product (aka binary). My theory is this is due to name mangling where the framework generates a different name than the unit test binary. I also strongly suspect this would happen for any type of dynamic library involving Swift generic classes but I haven't confirmed that.
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!