Home > other >  Clang: promoting warning for type-casting like id<protocol> to class<Protocol>?
Clang: promoting warning for type-casting like id<protocol> to class<Protocol>?

Time:06-03

I'm doing some code refactoring but facing a problem that clang has no any warning for this situation:

@protocol CommonProtocol <NSObject>
- (void)common;
@end
=========
@interface Foo : NSObject <CommonProtocol>
- (void)foo;
@end
=========
@interface Bar : NSObject <CommonProtocol>
@end
=========
static id<CommonProtocol> getObject(void) {
    return [Bar new];
}

Foo *casting = getObject(); /// ⚠️ there is no warning for this
[casting common];
[casting foo]; ///            
  • Related