[Issue 19823] New: std.range.dropOne doesn't drop the element when called after std.algorithm.iteration.filter
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Apr 24 19:13:38 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=19823
Issue ID: 19823
Summary: std.range.dropOne doesn't drop the element when called
after std.algorithm.iteration.filter
Product: D
Version: D2
Hardware: x86
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: jonas.alves at gmail.com
It seems that in some cases dropOne doesn't work when called after
std.algorithm.iteration.filter. In the example I'm pasting below it seems that
it only works when the 1st position in the array is not filtered out.
In production we had more complex cases where it would do the correct thing
when compiled with dmd, but it would not work when compiled with ldc2.
Anyone knows why? I didn't look at the source code, but it looks like buggy
code generation.
import std.range: dropOne;
import std.stdio: writefln;
import std.algorithm.iteration: filter;
import std.array: array;
void main() {
auto a = [1,2,3,4];
writefln("%s", a.filter!(a => a != 1).dropOne); // [2, 3, 4] WRONG
writefln("%s", a.filter!(a => a != 2).dropOne); // [3, 4]
writefln("%s", a.filter!(a => a != 3).dropOne); // [2, 4]
writefln("%s", a.filter!(a => a != 4).dropOne); // [2, 3]
writefln("%s", a.filter!(a => a == 1).dropOne); // []
writefln("%s", a.filter!(a => a == 2).dropOne); // [2] WRONG
writefln("%s", a.filter!(a => a == 3).dropOne); // [3] WRONG
writefln("%s", a.filter!(a => a == 4).dropOne); // [4] WRONG
writefln("%s", a.filter!(a => a != 1).array.dropOne); // [3, 4]
}
--
More information about the Digitalmars-d-bugs
mailing list