https://issues.dlang.org/show_bug.cgi?id=17652
Issue ID: 17652 Summary: [DIP1000] opApply allow to escape reference to scope variable Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: safe Severity: normal Priority: P1 Component: dmd Assignee: nob...@puremagic.com Reporter: mathias.l...@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. --