Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-15 Thread Michael Ash
On Wed, Oct 15, 2008 at 6:50 AM, Jonathan del Strother [EMAIL PROTECTED] wrote: Presumably you could override +(id)alloc to be +(MyClass)alloc on classes that you knew implemented ambiguous init methods? You could, but then every subclass of your class which defines its own init methods is then

Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-15 Thread Chris Suter
On Wed, Oct 15, 2008 at 9:03 PM, John Engelhart [EMAIL PROTECTED] wrote: On Oct 14, 2008, at 7:11 AM, Chris Suter wrote: You can't override the type for existing methods. For example, initWithString: always returns an id. You can define them as returning something different but the compiler

Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-15 Thread Jonathan del Strother
On Wed, Oct 15, 2008 at 11:36 AM, Chris Suter [EMAIL PROTECTED] wrote: On Wed, Oct 15, 2008 at 9:03 PM, John Engelhart [EMAIL PROTECTED] wrote: On Oct 14, 2008, at 7:11 AM, Chris Suter wrote: You can't override the type for existing methods. For example, initWithString: always returns an

Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-15 Thread John Engelhart
On Oct 14, 2008, at 7:11 AM, Chris Suter wrote: You can't override the type for existing methods. For example, initWithString: always returns an id. You can define them as returning something different but the compiler will ignore it. Just a clarification on this particular point- it is

[Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Oleg Krupnov
In my project I have two different, totally unrelated classes. @interface ClassA : NSObject{} -(id)initWithContext:(ContextA*)context; @end @interface ClassB : NSObject{} -(id)initWithContext:(ContextB*)context; @end The problem is that when I call ContextA* context = ...; [[ClassA alloc]

Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Chris Suter
On Tue, Oct 14, 2008 at 9:13 PM, Graham Cox [EMAIL PROTECTED] wrote: Isn't the problem here with the init method, rather than alloc? It's a problem with both. NSString et. al. return id because they are class clusters (and because it's the established convention), I believe the fact that

Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Oleg Krupnov
You are right, casting from alloc worked, thank you. Is it the recommended practice to always cast after alloc? I still have a question in this regard. If the alloc returns id, then, from the compiler's perspective, there can be two solutions: 1) assume that the id type can have each and any

Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Quincey Morris
On Oct 14, 2008, at 02:17, Oleg Krupnov wrote: If the alloc returns id, then, from the compiler's perspective, there can be two solutions: 1) assume that the id type can have each and any method and let it be resolved at run time without any compiler warning or 2) assume that the id does not

Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Chris Suter
On Tue, Oct 14, 2008 at 8:17 PM, Oleg Krupnov [EMAIL PROTECTED] wrote: You are right, casting from alloc worked, thank you. Is it the recommended practice to always cast after alloc? I still have a question in this regard. If the alloc returns id, then, from the compiler's perspective,

Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Roland King
Oleg Krupnov wrote: You are right, casting from alloc worked, thank you. Is it the recommended practice to always cast after alloc? Not really - the recommended practice is to have method names which have unique parameter types. Remember that Objective-C's notion of a selector is

Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Graham Cox
On 14 Oct 2008, at 8:17 pm, Oleg Krupnov wrote: You are right, casting from alloc worked, thank you. Is it the recommended practice to always cast after alloc? No, I never do it. I never see code that routinely does it either. I still have a question in this regard. If the alloc returns

Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Graham Cox
On 14 Oct 2008, at 8:58 pm, Chris Suter wrote: The proper way to solve this, in my opinion, is to allow a way of specifying that the return type varies depending on the class it's implemented on i.e. define the alloc method in such a way so that the compiler knows that -[class alloc] returns

Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Chris Suter
On Tue, Oct 14, 2008 at 7:43 PM, Oleg Krupnov [EMAIL PROTECTED] wrote: In my project I have two different, totally unrelated classes. @interface ClassA : NSObject{} -(id)initWithContext:(ContextA*)context; @end @interface ClassB : NSObject{} -(id)initWithContext:(ContextB*)context;

Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Graham Cox
On 14 Oct 2008, at 10:11 pm, Chris Suter wrote: I believe the fact that they are class clusters is irrelevant; it's an implementation detail. The objects returned still conform to the interfaces defined by NSString and NSMutableString. They return id, rather than NSString say, because

Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Greg Parker
Chris Suter wrote: The proper way to solve this, in my opinion, is to allow a way of specifying that the return type varies depending on the class it's implemented on i.e. define the alloc method in such a way so that the compiler knows that -[class alloc] returns an object of type class.