Bug 13085 – Compiler does not reject storing global reference to scope delegate

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2014-07-09T22:16:00Z
Last change time
2014-07-09T22:21:26Z
Keywords
accepts-invalid, wrong-code
Assigned to
nobody
Creator
hsteoh

Comments

Comment #0 by hsteoh — 2014-07-09T22:16:33Z
Code: ------ int delegate() globDg; void func(scope int delegate() dg) { globDg = dg; globDg(); } void sub() { int x; func(() { return ++x; }); } void trashme() { import std.stdio; writeln(globDg()); // prints garbage } void main() { sub(); trashme(); } ------
Comment #1 by hsteoh — 2014-07-09T22:17:58Z
The line "globDg = dg" should be rejected at compile-time, but isn't.
Comment #2 by hsteoh — 2014-07-09T22:21:26Z
*** This issue has been marked as a duplicate of issue 5270 ***