[Issue 19700] [2.085.0-beta.2] Obj-C wrong code overloading selectors and extern(D)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 26 19:52:29 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19700

--- Comment #1 from Jacob Carlborg <doob at me.com> ---
Here's the problem. What's happening in your example is that the whole NSString
class is overwritten. When a class is referenced and only declared, a specific
symbol is outputted by the compiler. When the class is defined as well
additional symbols are outputted as well. Since these symbols are located in
the object file the linker won't search for them in external libraries.

It's the same thing as doing:

extern (C) void* malloc(size_t size)
{
    return null;
}

I currently don't have a good way to determine if a class is externally defined
or not. The current implementation will assume that it is externally defined if
none of the methods have a body. This is not an ideal solution, it causes this
problem, as you have noticed. It's also not possible to have an empty subclass.
I think the original implementation required to use `extern (Objective-C)` on
externally defined classes and  not use it on internally defined classes. That
requires that all classes defined in D inherit from an externally defined
class. This is true most of the time, the Objective-C compiler will warn if you
don't inherit from a class.

In Objective-C this is easily handled by having two separate keywords for
declarations and definitions:

@interface Foo // declaration of a class named Foo
@end

@implementation Foo // definition of Foo
@end

I'll try to figure out how this is handled in Swift.

--


More information about the Digitalmars-d-bugs mailing list