Fix-it for Swift 3 renamed generic method call fails, manual conversion gives errors
| Originator: | benchatelain | ||
| Number: | rdar://27141382 | Date Originated: | 2016-07-01 |
| Status: | Resolved | Resolved: | 2016-07-05 |
| Product: | Developer Tools | Product Version: | Xcode 8.0 beta (8S128d), Default Swift toolchain |
| Classification: | Serious Bug | Reproducible: | Always |
In general, the fix-it suggestions are very good if not spot-on for methods renamed due to the Grand Renaming in Swift 3. However, I’ve stumbled across a case where the fix-it generates invalid code. Additionally, manually converting the method call to the new format generates nonsensical compiler errors.
The original method signature has no argument label:
public func objects<T: Object>(type: T.Type) -> Results<T>
The renamed version adopting the Swift 3 naming convention with a required argument label:
public func allObjects<T: Object>(ofType type: T.Type) -> Results<T>
Callers of this method need to change from the first to the second form:
- realm.objects(T)
- realm.allObjects(ofType: T.Type)
Steps to Reproduce:
1. Clone the Xcode project located at https://github.com/phatblat/RealmAllObjectsOfTypeSwift3
2. Run `git submodule update —init` to pull down the Realm projects
3. Check out the “before” tag
4. Build the project
- Click on the fix-it suggestion for the objects(T) method call
Expected Results:
The Xcode fix-it will identify the renamed method (works) and applying it will change the call to the following:
allObjects(ofType: T.Type)
Actual Results:
The fix-it places the opening parentheses after the argument label, colon and space, generating invalid code.
allObjectsofType: (T)
Additionally, the correct method call syntax generates 2 compiler errors even when manually migrated:
- cannot create a single-element tuple with an element label
- missing argument label 'ofType:' in call
Configuration: (hardware)
MacBook 12-inch (MacBook8,1), Early 2015
Version & Build:
Xcode 8.0 beta 1 (8S128d)
OS X 10.12 beta 1 (16A201w)
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!
Fixed in Xcode 8b2
Both the incorrect fix-it issue and odd compiler errors are resolved in Xcode 8 beta 2 (8S162m)