Bug 17652 – [DIP1000] opApply allow to escape reference to scope variable

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-07-14T15:25:08Z
Last change time
2018-03-04T07:46:40Z
Keywords
accepts-invalid, safe
Assigned to
No Owner
Creator
Mathias Lang

Comments

Comment #0 by mathias.lang — 2017-07-14T15:25:08Z
``` 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.
Comment #1 by bugzilla — 2018-03-04T07:46:40Z
It does check it now: test.d(10): Error: function `test4.Foo.opApply` `(scope int delegate(scope Object) @nogc @safe dg)` is not callable using argument types `(int delegate(Object object) pure nothrow @nogc @safe)`