www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17652] New: [DIP1000] opApply allow to escape reference to


          Issue ID: 17652
           Summary: [DIP1000]  opApply allow to escape reference to scope
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: safe
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: mathias.lang sociomantic.com

void main ()  safe  nogc
    Object o = leak();
    assert(o !is null);

Object leak ()  safe  nogc
    Foo f;
    foreach (object; f)
        if (object !is null)
            return object;
    return null;

struct Foo
    alias DgType = int delegate (scope Object)  safe  nogc;
    public int opApply (scope DgType dg)  safe  nogc
        scope o = new Object;
        return dg(o);

The compiler doesn't properly check the type of the delegate it passes to
`opApply`, allowing to pass a delegate which needs a non-scope parameter.

Jul 14 2017