On or about 4/26/10 1:22 PM, thus spake "Greg Parker" <gpar...@apple.com>:

> On Apr 26, 2010, at 1:01 PM, Matt Neuburg wrote:
>> Here's my test:
>> MyClass:
>> - (void) tryme: (NSString*) s;
>> MyClass2:
>> - (void) tryme: (NSArray*) s;
>>    MyClass* thing = [[MyClass alloc] init];
>>    NSString* s = @"Howdy";
>>    [(id)thing tryme: s];
>> 
> In this test, the mismatch is an NSString* parameter vs an NSArray* parameter.
> That mismatch is "safe": the compiled code for the call site looks the same
> either way. The compiler does not warn about this by default.

Thanks for this extensive reply; it taught me a lot.

Here's something interesting. If I reverse the declaration order of MyClass
and MyClass2, like this:

>> MyClass2:
>> - (void) tryme: (NSArray*) s;
>> MyClass:
>> - (void) tryme: (NSString*) s;
>>    MyClass* thing = [[MyClass alloc] init];
>>    NSString* s = @"Howdy";
>>    [(id)thing tryme: s];

...Now the compiler *does* complain about that last line - it ways I'm
passing a string when an array was expected.

So I guess the compiler treats the *first* declaration of a method
name-and-signature that it encounters as the "real" one.

Now, that's okay, I guess (especially since there's a warning I can turn on
to detect even this level of conflict - thanks for explaining about that),
as long as the compiler is correctly foreshadowing the behavior of the
runtime. I take it from what you say about the compiled code being the same
that it is... m.

-- 
matt neuburg, phd = m...@tidbits.com, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
AppleScript: the Definitive Guide, 2nd edition
http://www.tidbits.com/matt/default.html#applescriptthings
Take Control of Exploring & Customizing Snow Leopard
http://tinyurl.com/kufyy8
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to