Warnings when defining methods which take a block using an obj-c class's generic type
| Originator: | jp | ||
| Number: | rdar://29679268 | Date Originated: | 15-Dec-2016 12:14 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 8.2 (8C38) |
| Classification: | Other Bug | Reproducible: | Always |
This is a duplicate of rdar://23711954
Summary:
Trying to use a generic objective-c class's type in a generic type of a block parameter works when declaring methods, but not when defining them, but not using them produces a warning about mismatched parameter types. For example:
@interface MyContainer <ObjectType: NSObject *> : NSObject
// Declaring methods works fine:
- (void)foo:(void (^)(MyContainer<ObjectType> *))block;
- (void)bar:(void (^)(MyContainer<ObjectType> *))block;
- (void)baz:(ObjectType)obj;
@end
@implementation MyContainer
// With the generic type:
// error: No type or protocol named 'ObjectType'
// warning: conflicting parameter types in implementation of 'foo:': 'void (^__strong)(MyContainer<ObjectType> *__strong)' vs 'void (^__strong)(MyContainer *__strong)'
- (void)foo:(void (^)(MyContainer<ObjectType> *))block {
block(self);
}
// Without the generic type:
// warning: conflicting parameter types in implementation of 'bar:': 'void (^__strong)(MyContainer<ObjectType> *__strong)' vs 'void (^__strong)(MyContainer *__strong)'
- (void)bar:(void (^)(MyContainer *))block {
block(self);
}
// Using NSObject rather than ObjectType does not produce a warning when
// it isn't a block parameter
- (void)baz:(NSObject *)obj {
(void)obj;
}
Version:
Xcode 8.2 (8C38)
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!