[Issue 23976] std.range.slide fails in dmd-2.104.0
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jun 7 08:02:29 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=23976
cbleser <cr at tagion.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |cr at tagion.org
--- Comment #1 from cbleser <cr at tagion.org> ---
Created attachment 1880
--> https://issues.dlang.org/attachment.cgi?id=1880&action=edit
unittest which shows the bug
The bug occurs in the latest version dmd-2.104.0 but works in dmd-2.103.1 and
older.
The problem is when a slide(2) is taken of a rbtree range the last element
contains 1 element and not two.
But it only fails in combination with rbtree as far as I know.
The sample code is as follows.
```
import std.container.rbtree;
import std.range;
import std.stdio;
import std.algorithm;
struct RecycleSegment {
int index;
// uint size;
}
alias Indices = RedBlackTree!(RecycleSegment*, (a, b) => a.index < b.index); //
RecycleSegment: sorted by size.
unittest {
const a=[17,42];
writefln("%s", a.slide(2));
// This passes for both dmd-2.103.1 and dmd-2.104.0
assert(a.slide(2).map!(r => r.walkLength == 2).all);
auto indices = new Indices;
indices.insert(new RecycleSegment(42));
indices.insert(new RecycleSegment(17));
writefln("%s", indices[].slide(2));
writefln("%s", indices[].slide(2).map!(r => r.walkLength == 2));
// This passes in dmd-2.103.1 but fails in dmd-2.104.0
assert(indices[].slide(2).map!(r => r.walkLength == 2).all);
}
```
This is the print out of dmd-1.103.1
```
[[17, 42]]
[[7F6E7F100020, 7F6E7F100010]]
[true]
```
And this is the print out of dmd-1.104.0 (Where it fails in the last assert)
```
[[17, 42]]
[[7F7622B00020, 7F7622B00010], [7F7622B00010]]
[true, false]
slide_bug.d(23): [unittest] unittest failure
```
As can be seen, the last slide has one element but it should not even be in the
new list.
But for some reason, it works with a simple array.
I hope this help to fix it.
Thanks.
--
More information about the Digitalmars-d-bugs
mailing list