[Issue 8905] DList.Range: Internal error, inconsistent state

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Oct 29 14:52:01 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8905


monarchdodra at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra at gmail.com


--- Comment #1 from monarchdodra at gmail.com 2012-10-29 14:51:58 PDT ---
(In reply to comment #0)
> The code:
> 
> import std.container;
> import std.algorithm;
> import std.stdio;
> 
> void main() {
>     DList!int list = make!(DList!int)(1,2,3,4);
>     auto range = list[];
>     list.stableRemoveBack();
>     list.stableInsertBack(7);
>     writeln(list[]);
>     writeln(range);
> }
> 
> The fireworks:
> 
> core.exception.AssertError@/usr/include/dmd-d/std/container.d(1573):
> DList.Range: Internal error, inconsistent state

I inserted that assert in the code.

I think the code is invalid, that is not how "stable" is meant to be used. It
just means that the insert will not modify the order of the *other* elements in
the list.

The documentation states otherwise, but in this case, I think it is the
documentation that is wrong.

When you first call "stableRemoveBack", the range becomes invalidated. That is
what the assert is telling you.

Case in point, in DMD 2.060, without the assert, look at what happens when you
do this:

//----
import std.range;
import std.container;
import std.algorithm;
import std.stdio;

void main() {
   DList!int list = make!(DList!int)(1,2,3,4);
   auto range = list[];
   list.stableRemoveBack();
   list.stableInsertBack(7);
   writeln(range);
   writeln(range.retro());
}
//----
[1, 2, 3, 7]
[4, 3, 2, 1]
//----

Notice the '7' when iterating forward, but the 4 when iterating backwards: The
tip of the range's front is not the tail: The range got "cut" on the call to
"stableRemoveBack" and that is why the range is not happy.

I don't think there is *ANY* way to ever make this work, and I'd suggest either
of:
*Re-writing the documentation.
*Removing the function if the documentation is correct.

--------
EDIT: ACTUALLY, one of the first things I'll propose is to reword the assert:
It makes it sound like an implementation error, when it is actually a user
error. How about: "Logic Error: The DList.range chain has been cut."

I know it might not make that much sense, but it is what is happening, and the
message *is* better. BTW, this thread might make sense of what is happening:

http://forum.dlang.org/thread/gjhclwsuqyhrimdeoaec@forum.dlang.org

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list