Swift: compiler chooses function overload with the wrong type
| Originator: | indragiek | ||
| Number: | rdar://17412596 | Date Originated: | 22-Jun-2014 |
| Status: | Open | Resolved: | No |
| Product: | Developer Tools | Product Version: | OS X 10.10 (14A261i), Xcode 6.0 (6A216f) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary: In the sample code attached, there is a function `ALOperand.equalTo()` that is overloaded. 2 versions of `equalTo()` are defined: one that expects an `ALOperand` as its argument, and one that expects a `CGFloat`. In the method `SwiftAutoLayoutTests.testRelationsWithoutSecondView()`, it uses the overloaded `==` operator, which is intended to call the version of `equalTo` that expects a `CGFloat` but ends up calling the one that expects an `ALOperand` instead, causing an EXC_BAD_ACCESS crash at runtime. Steps to Reproduce: 1. Run the test method `testRelationsWithoutSecondView()` in SwiftAutoLayoutTests 2. Wait for it to crash with EXC_BAD_ACCESS 3. Go through the stack trace and note that it is calling the `equalTo()` function that accepts an `ALOperand` as an argument instead of a `CGFloat` Expected Results: Calls the `equalTo()` function that expects a `CGFloat` as an argument. Actual Results: Calls the `equalTo()` function that expects an `ALOperand` as an argument, resulting in a crash. Version: OS X 10.10 (14A261i), Xcode 6.0 (6A216f) Notes: Configuration: Attachments: 'SwiftAutoLayout.zip' was 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!
Working as of Xcode 7.1
At least in Xcode 7.1 this problem has been resolved.
Code: http://cl.ly/3S0a1T0Q0S1D