On 08/09/2013 11:05 AM, Luboš Doležel wrote:
> Is it possible that there are two different selectors with the same name
> in the system, one invokes the superclass' implementation and the other
> one invokes the the subclass' implementation?
> 

Okay, this is now confirmed.

This code works as expected:

#include <Foundation/NSObject.h>
extern "C" void testMe(id c)
{
        id obj = [c alloc];
        [obj initWithFrame: 0];
}

If I add #include <AppKit/NSView.h>, the the compilation starts failing
(clang).

error: no viable conversion from 'int' to 'NSRect' (aka '_NSRect')
/usr/local/include/AppKit/NSView.h:161:31: note: passing argument to
parameter 'frameRect' here
- (id) initWithFrame: (NSRect)frameRect;

Which is quite interesting, because I never stated that "obj" is of type
NSView*, it is still just "id". Is it legal for compiler to assume that?

And once I correct the compile error and supply a NSRect() in arguments,
then things break and initWithFrame: in class "c" is not invoked any
more. initWithFrame: in super class (NSView) is invoked instead.

I assume that this has something to do with typed selectors, since the
type info used for initWithFrame: in the subclass is different.

But is this behavior correct? I assumed that type information was only
supposed to be used for runtime checks (warnings) and shouldn't affect
where the message gets delivered.

-- 
Luboš Doležel


_______________________________________________
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to