D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10666 - Appender does not work with a RefCounted type
Summary: Appender does not work with a RefCounted type
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-18 06:59 UTC by Andrej Mitrovic
Modified: 2020-03-21 03:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2013-07-18 06:59:59 UTC
-----
import std.array;
import std.typecons;

struct T { }

struct S
{
    RefCounted!T data;
}

void main()
{
    Appender!(S[]) arr;
    arr.put(S());
}
-----

2.064:
$ dmd test.d
> C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\array.d(2287): Error: variable std.array.Appender!(S[]).Appender.put!(S).put.item has scoped destruction, cannot build closure

However there is another bug in earlier releases:

2.063:
$ dmd test.d
$ test.exe

On win32 this crashes with a dialog box:

-----
[Window Title]
test.exe

[Main Instruction]
test.exe has stopped working

[Content]
A problem caused the program to stop working correctly. Please close the program.

[Close the program] [Debug the program]
-----

I've traced down the first version that crashes:

2.053:
> Crash

Earlier releases simply have an assertion failure:

2.052:
> core.exception.AssertError@std.typecons(2351): Assertion failure

The code which failed there is:

-----
assert(RefCounted._store._count > 0);
-----
Comment 1 Kenji Hara 2013-09-10 18:05:31 UTC
(In reply to comment #0)
> 2.064:
> $ dmd test.d
> > C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\array.d(2287): Error: variable std.array.Appender!(S[]).Appender.put!(S).put.item has scoped destruction, cannot build closure

The error reporting is a rejects-valid compiler bug.

https://github.com/D-Programming-Language/dmd/pull/2548
Comment 2 Kenji Hara 2013-09-10 18:07:31 UTC
(In reply to comment #1)
> (In reply to comment #0)
> > 2.064:
> > $ dmd test.d
> > > C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\array.d(2287): Error: variable std.array.Appender!(S[]).Appender.put!(S).put.item has scoped destruction, cannot build closure
> 
> The error reporting is a rejects-valid compiler bug.
> 
> https://github.com/D-Programming-Language/dmd/pull/2548

After the compiler fix applied, the OP code with runtime crash will reproduce.
Comment 3 github-bugzilla 2013-09-14 23:50:31 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/59af1d08e75f14c8082f81b546a12b21b30e5d3b
Partial fix for Issue 10666 - Appender does not work with a RefCounted type

Essentially this is neigher dmd nor phobos regression, but recent Appender change in 2.064a should not raise "cannot build closure" error.

https://github.com/D-Programming-Language/dmd/commit/aea5806539d9073c85bc7533a6177af6cf6465cb
Merge pull request #2548 from 9rnsr/fix10666

Partial fix for Issue 10666 - Appender does not work with a RefCounted type
Comment 4 Brad Roberts 2013-10-06 20:28:12 UTC
Is there anything left of this bug to fix before closing it?
Comment 5 Andrej Mitrovic 2013-10-07 07:35:23 UTC
(In reply to comment #4)
> Is there anything left of this bug to fix before closing it?

Yes, this runtime bug has to be fixed:
core.exception.InvalidMemoryOperationError
Comment 6 Andrej Mitrovic 2013-10-07 07:36:53 UTC
However it shouldn't be filed as a regression anymore, fixing that.