www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19700] New: [2.085.0-beta.2] Obj-C wrong code overloading

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

          Issue ID: 19700
           Summary: [2.085.0-beta.2] Obj-C wrong code overloading
                    selectors and extern(D)
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: destructionator gmail.com

Consider this code:

---

extern (Objective-C)
class NSObject {}

extern (Objective-C)
class NSString : NSObject {
        NSString init()  selector("init");
        static NSString alloc()  selector("alloc");

        const(char)* UTF8String()  selector("UTF8String");

        NSString initWithBytes(
                const(void)* bytes,
                size_t length,
                size_t encoding
        )  selector("initWithBytes:length:encoding:");

        version(broken)
        extern(D) NSString init(string s) { return initWithBytes(s.ptr,
s.length, NSUTF8StringEncoding); }
}

enum NSUTF8StringEncoding = 4;

void main() {
        auto s = "hello";
        auto str = NSString.alloc.initWithBytes(s.ptr, s.length,
NSUTF8StringEncoding);

}

---


If you COMMENT OUT or REMOVE the version(broken) code, it runs without error.

But if that line is in the program - even when versioned out!! - it gives a
runtime error: "[NSString initWithBytes:length:encoding:]: unrecognized
selector sent to instance ....."

I think the mere presence of a non-objc overload in the class throws off some
of the runtime glue code (though the error appears to give the right now... is
that trying to call a static method when it is supposed to instance though?).

--
Feb 26 2019