Xcode 7: `auto` does not preserve Objective–C++ generics when indirected
| Originator: | steipete | ||
| Number: | rdar://21765827 | Date Originated: | 10-Jul-2015 04:33 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | 7.0 beta 3 (7A152u) |
| Classification: | Other Bug | Reproducible: | Always |
Summary:
In Objective–C++ code, using the `auto` keyword correctly preserves type annotations for e.g. NSArray return values, such as the following:
// given that view is some UIView *:
auto const interestingViews = view.subviews;
// interestingViews is of type NSArray<__kindof UIView *> *const -- as expected
If, however, those values are indirected through other generic class methods, the type annotations are lost:
// again we have some UIView *view:
auto const viewsToFilter = [NSMutableArray arrayWithArray:view.subviews];
// type information is lost: viewsToFilter is of type NSMutableArray *const
// even though arrayWithArray: is annotated with ObjectType
// i.e. it _should_ produce NSMutableArray<ObjectType> *
Steps to Reproduce:
1. Create a new iOS single view app project in Xcode 7
2. Change the view controller’s implementation file extension to .mm
3. In the viewDidLoad method, after the super call add the line `auto view = self.view;`
4. Copy and paste the code snippets from the description in there.
5. Observe the types in the auto completion list when you type `viewsT` and `intere`
Expected Results:
`intere` yields `interestingViews` with a type of `NSArray<__kindof UIView *> *const` in the auto complete list, `viewsT` yields `viewsToFilter` with a type of `NSMutableArray<__kindof UIView *> *const` in the auto complete list
Actual Results:
`intere` yields `interestingViews` with a type of `NSArray<__kindof UIView *> *const` in the auto complete list — that’s good.
`viewsT` yields `viewsToFilter` with a type of `NSMutableArray *const` in the auto complete list — that’s bad: the type annotation has been swallowed.
Version:
Happens in all Xcode 7 seeds, last checked with Version 7.0 beta 3 (7A152u)
Notes:
This is a duplicate of rdar://21765641
Configuration:
Attachments:
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!