• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: why doesn't the compiler complain?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why doesn't the compiler complain?


  • Subject: Re: why doesn't the compiler complain?
  • From: Jens Alfke <email@hidden>
  • Date: Mon, 26 Apr 2010 13:20:20 -0700


On Apr 26, 2010, at 1:01 PM, Matt Neuburg wrote:

"Methods in different classes that have the same selector (the same name)
must also share the same return and argument types. This constraint is
imposed by the compiler..."

It's more like "should", and the reason is because of the ambiguity of sending the message when the receiver type isn't known. In my experience you just get a warning when the parser has seen two incompatible declarations of the same selector and tries to resolve its use in a message to 'id'.


   MyClass* thing = [[MyClass alloc] init];
   NSString* s = @"Howdy";
   [(id)thing tryme: s];

This, too, compiles with no problem. Why is the compiler not complaining
that tryme: is ambiguous? Isn't that what it's supposed to do? (That is why
I cast to an id, so that the compiler wouldn't be able to resolve tryme:.)

I would also expect a warning there. Had the parser seen both MyClass and MyClass2's interfaces by that point, i.e. did you #import both of their headers?


—Jens_______________________________________________

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


References: 
 >why doesn't the compiler complain? (From: Matt Neuburg <email@hidden>)

  • Prev by Date: why doesn't the compiler complain?
  • Next by Date: Re: why doesn't the compiler complain?
  • Previous by thread: why doesn't the compiler complain?
  • Next by thread: Re: why doesn't the compiler complain?
  • Index(es):
    • Date
    • Thread