www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17315] New: Assigning a delegate to a function compiles but


          Issue ID: 17315
           Summary: Assigning a delegate to a function compiles but causes
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: major
          Priority: P3
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: tomerfiliba gmail.com

using `DMD64 D Compiler v2.073.0` on ubuntu 16.04


class Base {
    __gshared static Base function()[string] registry;
    static Base load(string name) {return registry[name]();}

class Child: Base {
    shared static this() {
        import std.traits: fullyQualifiedName;
        registry[fullyQualifiedName!(typeof(this))] = &_load;   // <<< this
shouldn't compile

    Base _load() {return new typeof(this);}

void main() {
    auto inst = Base.load("dtest.Child");  // segfault


Program received signal SIGSEGV, Segmentation fault.
0x0000000000453f4a in invariant._d_invariant(Object) ()
(gdb) bt
#0  0x0000000000453f4a in invariant._d_invariant(Object) ()
#1  0x0000000000440272 in dtest.Child._load() (this=0x477d7b <_TMP1+11>) at
#2  0x00000000004401ad in dtest.Base.load(immutable(char)[]) (name=...) at
#3  0x000000000044029c in D main () at src/dtest.d:81


if i make `_load` a static function (as it should be), everything works as

class Child: Base {
    static Base _load() {return new typeof(this);}

Apr 10 2017