[cfe-dev] Bug (and patch) in objc method lookup

Jean-Daniel Dupas devlists at shadowlab.org
Thu Feb 26 02:22:49 PST 2009


A path to solve a method lookup issue with protocol chain.
Uses lookupClassMethod()  and lookupInstanceMethod() instead of  
getClassMethod() and getInstanceMethod() on each declared protocol, so  
clang will also search in inherited protocol and not just in the leaf  
protocol.



A simple example to explain the problem:

-------------------------------- protocol-chain.m  
--------------------------------
@protocol ProtocolA

+ (id)classMethod;
- (id)instanceMethod;

@end

@protocol ProtocolB <ProtocolA>

@end

@interface Foo : NSObject <ProtocolB> { }

@end

@interface SubFoo : Foo { }

@end

@implementation SubFoo

+ (id)method {
   return [super classMethod];
}

- (id)method {
   return [super instanceMethod];
}

@end
------------------------------------------------------------------------------------------------
protocol-chain.m:30:10: warning: method '+classMethod' not found  
(return type defaults to 'id')
   return [super classMethod];
          ^~~~~~~~~~~~~~~~~~~
protocol-chain.m:34:10: warning: method '-instanceMethod' not found  
(return type defaults to 'id')
   return [super instanceMethod];
          ^~~~~~~~~~~~~~~~~~~~~~
2 diagnostics generated.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090226/5f368b91/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: protocol-lookup.patch
Type: application/octet-stream
Size: 974 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090226/5f368b91/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090226/5f368b91/attachment-0001.html>


More information about the cfe-dev mailing list