Bug 10928 – Fails to create closures that reference structs with dtor

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-30T07:58:00Z
Last change time
2014-08-10T12:54:45Z
Assigned to
nobody
Creator
dmitry.olsh

Comments

Comment #0 by dmitry.olsh — 2013-08-30T07:58:43Z
To make example real simple: struct D{ int x; ~this() { } } void foo(D bar) { (){ bar.x++; }(); } void main() { foo(D.init); } Note that even though there is no need for allocating closure at all. Compiler should deal with such cases by tiying the lifetime of dtor-able variables to that of a closure if one is indeed required. This is critical as std.array.array and other functions started using internal lambdas for trusted blocks making use of any RefCounted range impossible.
Comment #1 by dmitry.olsh — 2013-08-30T07:59:13Z
Error message: d_test.d(10): Error: variable d_test.foo.bar has scoped destruction, cannot build closure
Comment #2 by joseph.wakeling — 2013-08-30T08:31:42Z
For reference, an "in-the-wild" example of such an error: http://forum.dlang.org/post/[email protected] http://forum.dlang.org/thread/[email protected] This is a concern as it potentially blocks the ability to move forward with necessary redesign work on random number generation in Phobos.
Comment #3 by monarchdodra — 2013-08-30T08:47:35Z
(In reply to comment #2) > For reference, an "in-the-wild" example of such an error: > http://forum.dlang.org/post/[email protected] > http://forum.dlang.org/thread/[email protected] > > This is a concern as it potentially blocks the ability to move forward with > necessary redesign work on random number generation in Phobos. Currently, a *workaround* is to avoid lambdas in favor of named: //---- struct D { int x; ~this() { } } void foo(D bar) { void do_it(){ bar.x++; } do_it(); } void main() { foo(D.init); } //----
Comment #4 by github-bugzilla — 2013-09-01T01:13:48Z
Comment #5 by code — 2013-12-27T14:31:57Z
Also see bug 11382
Comment #6 by github-bugzilla — 2014-08-10T12:54:43Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/4b9df682679b7792aa48a32aa343d3dd63a6a3ad fix Issue 10928 - Fails to create closures that reference structs with dtor