[Swift] Can't overload method and a function with the same name and different type signatures.
| Originator: | adam.kuipers | ||
| Number: | rdar://23052929 | Date Originated: | 9-Oct-2015 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 7.0.1 / Swift 2 |
| Classification: | Other Bug | Reproducible: | Always |
Summary: In Swift, if a method and a function share a name but have separate type signatures, the class of the method can't apply the global function. See: attached playground or Swift file. Steps to Reproduce: All code in Swift. You can also see attached playground/Swift file. 1. Open a Swift file/playground. 2. Write a file level/global function. 3. Write a class with a method that shares a name with the aforementioned global function but has a separate type signature. 4. Use global function inside class. 5. Try to compile and despair. Expected Results: Code compiles, class is able to use global function normally. Actual Results: Code doesn't compile. Version: Xcode 7.0.1 Notes: One can get around this by name mangling the global function herself. If you see the attached playground/file, that's what I did for the method `doBimpyWith2`. This isn't ideal for API's where the client can call on either global functions or methods as a shorthand. Configuration: Always occurs in Swift 2. Didn't try on Swift 1 Attachments: 'FunctionOverloadingBug.playground.zip' and 'FunctionOverloadingBug.swift' were successfully uploaded.
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!
Attached source code.
https://gist.github.com/adamkuipers/1126ad09a0478d64f069