www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17449] New: [DIP1000] crash due to covariant conversion of


          Issue ID: 17449
           Summary: [DIP1000] crash due to covariant conversion of scope
                    delegate to delegate
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: r.sagitario gmx.de

From the dmd testsuite, runnable/xtest46.d:
module test; struct Event9834 { void delegate() dg; void set(void delegate() h) pure { dg = h; } // AV occurs void call() { dg(); } } void main() { Event9834 ev; auto a = new class { Object o; this() { o = new Object; ev.set((){ o.toString(); }); } }; ev.call(); } This runs fine when compiled with "dmd test", but crashes with an access violation when compiled with "dmd test -dip1000". This is caused by the delegate being inferred as "scope", and implicitely converted to a non-scope delegate (thus not having a closure). This is ok when the delegate is called by the callee (Event9834.set) directly, but not if it is saved for later invocation. --
May 28 2017