www.digitalmars.com         C & C++   DMDScript  

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

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

          Issue ID: 17315
           Summary: Assigning a delegate to a function compiles but causes
                    segfault
           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


src/dtest.d:69

src/dtest.d:60


===========================================

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

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

--
Apr 10 2017