Skip navigation.
 
ml[Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning
FROM : Oleg Krupnov
DATE : Tue Oct 14 10:43:35 2008

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] initWithContext:context];

Not in all cases, but in some I get the warning that the var "context"
is of different type (ContextA) than expected (ContextB). It seems
like the compiler erroneously resolves this call to ClassB instead of
ClassA, I guess because the two methods have the same name. This
problem disappears if I rename one of the methods to
"initWithContext2".

I'd like to keep the same name and I hate the compiler warning. Is
there any resolution? Is it really a bug of the Obj-C compiler?

Related mailsAuthorDate
ml[Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning Oleg Krupnov Oct 14, 10:43
mlRe: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning Chris Suter Oct 14, 11:00
mlRe: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning Oleg Krupnov Oct 14, 11:17
mlRe: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning Roland King Oct 14, 11:47
mlRe: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning Graham Cox Oct 14, 11:52
mlRe: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning Chris Suter Oct 14, 11:58
mlRe: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning Graham Cox Oct 14, 12:13
mlRe: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning Chris Suter Oct 14, 13:11
mlRe: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning Graham Cox Oct 14, 13:31
mlRe: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning Quincey Morris Oct 14, 18:59
mlRe: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning John Engelhart Oct 15, 12:03
mlRe: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning Chris Suter Oct 15, 12:36
mlRe: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning Jonathan del Strot… Oct 15, 12:50
mlRe: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning Michael Ash Oct 15, 16:17