views:

364

answers:

1

I am currently trying to compile OCMock with GCC4.2 (original: 4.0) and start getting the following warning:

warning: passing argument 1 of 'partialMockForObject:' from distinct Objective-C type

the calling method is:

- (void)forwardInvocationForRealObject:(NSInvocation *)anInvocation
{
    // in here "self" is a reference to the real object, not the mock
    OCPartialMockObject *mock = [OCPartialMockObject partialMockForObject:(id)self];
    // ...
}

and the called method is:

+ (id)partialMockForObject:(NSObject *)anObject;

prefixing the argument with a cast to id fixes the problem. I thought all objects were subclass of NSObject and though the cast would be made implicit (super class substitution: a super class can always be replaced by any child class of it)

+2  A: 

All objects are not necessarily descended from NSObject. Most Cocoa classes are (NSProxy is the only exception that occurs off the top of my head), but if you don't declare a class as being descended from NSObject, it won't be. Could it be that you forgot that in the declaration of wherever this occurs?

Chuck
it really is a NSProxy deriving class. Will a cast to (id) work? Thanks a lot, i will mark it as the correct answer.
Johannes Rudolph
@Johannes: Almost certainly. I know in other versions of that framework the method signature had an argument type of id, and NSProxy will respond to anything the object on the other end does.
Chuck