Re: why doesn't the compiler complain?
Re: why doesn't the compiler complain?
- Subject: Re: why doesn't the compiler complain?
- From: Matt Neuburg <email@hidden>
- Date: Tue, 27 Apr 2010 09:05:32 -0700
- Thread-topic: why doesn't the compiler complain?
On or about 4/26/10 1:22 PM, thus spake "Greg Parker" <email@hidden>:
> The compiler warns more aggressively for mismatches that do affect the call
> site's code. Those are more likely to be actual bugs, rather than correct but
> loosely-typed code. For example, if you change your example's parameter types
> to NSString* vs int, you'll get the warning even without any extra warning
> flags.
Just to clarify: you get the warning, but only when you try to *call* the
method that has multiple definitions (and then only when using dynamic
typing, of course).
In other words, this code by itself does not generate any warning:
@interface MyClass : NSObject {
}
- (void) tryme: (NSString*) s;
@end
@implementation MyClass
- (void) tryme: (NSString*) s {
;
}
@end
@interface MyClass2 : NSObject {
}
- (void) tryme: (int) s;
@end
@implementation MyClass2
- (void) tryme: (int) s {
;
}
@end
I guess I was hoping and expecting that the above would be sufficient to
generate a warning ("hey, you've defined methods with the same name but
different signatures; this could lead to trouble"). But the compiler is
silent.
I see now, however, *why* the compiler is silent: it's because it weren't,
it would be too chatty. I turned on -Wselector and got 114 warnings... :)
m.
--
matt neuburg, phd = email@hidden, 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 (email@hidden)
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:
This email sent to email@hidden