www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18738] New: [scope] scope delegates can be escaped via closure


          Issue ID: 18738
           Summary: [scope] scope delegates can be escaped via closure
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: default_357-line yahoo.de

Consider the following code:

int delegate()  safe foo(scope int delegate()  safe dg)  safe
    return { return dg(); };

int delegate()  safe bar()  safe
    int k = 5;
    return foo({ return k; });

void main()  safe
    writefln("%s", bar()());

The writefln outputs random noise because k is out of scope.

Doesn't seem very safe...

Probably foo should not have been allowed to allocate a closure that captured a
scope delegate parameter.

Apr 06 2018