[cfe-dev] Objective-C really strong type checking

Fariborz Jahanian fjahanian at apple.com
Wed Sep 8 13:19:32 PDT 2010


On Sep 8, 2010, at 12:08 PM, Marcin Świderski wrote:

> 2010/9/8 Fariborz Jahanian <fjahanian at apple.com>
>
> On Sep 8, 2010, at 11:05 AM, Ted Kremenek wrote:
>
> On Sep 8, 2010, at 2:01 AM, Marcin Świderski wrote:
>
> Hi All
>
> Is there a check implemented in Clang Checker (maybe not released  
> for XCode yet) that would find errors like in example:
>
> @interface SomeClass : NSObject {
>  NSMutableDictionary *_someObjects;
> }
> @end
>
> @implementation SomeClass
> - (id)init {
>  if ((self = [super init])) {
>   _someObject = [NSMutableArray new];
>  }
>  return self;
> }
> @end
>
> Methods 'new' or 'init' return object of type 'id' by convention,  
> but as I experienced it myself it can be unsafe.
>
> Cheers
> Marcin
>
> This isn't implemented, but it would be a great check and would be  
> really easy to do.
> Problem with this is that this is very common form of assignments in  
> objc and checker will get very noisy.
>
> - Fariborz
>
> Maybe you missed the point: there's NSMutableArray object assigned  
> to attribute of NSMutableDictionary type, and those types have  
> completly different interfaces. If the programmer would realy want  
> this, he could use attribute of type 'id' and live with possibility  
> of runtime errors.

So, this is more than just warn on assigning an 'id' expression to a  
static type. Checker should treat  [NSMutableArray new] specially and  
see how it gets used.
Thanks for the explanation.

- Fariborz

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100908/06303803/attachment.html>


More information about the cfe-dev mailing list