Bug 19681 – std.range.padRight.popFront does not correctly adjust length
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2019-02-16T20:55:34Z
Last change time
2019-02-18T14:09:31Z
Assigned to
No Owner
Creator
Jon Degenhardt
Comments
Comment #0 by jrdemail2000-dlang — 2019-02-16T20:55:34Z
padRight.popFront doesn't correctly decrement popFront.length. This will occur if padRight extended the source range. Test case:
---- test.d ----
import std.range;
import std.stdio;
void main(string[] args)
{
auto r = [1, 2, 3, 4].padRight(0, 6);
writeln(r.length);
r.popFront;
writeln(r.length);
}
---- Run ------
$ rdmd test.d
6
6
The second value should have been 5.
The underlying cause is that padRight.length() returns the max of the original padded length and the length of the source range. However, padRight.popFront adjusts only the source range, leaving the original padded length unchanged.
Comment #1 by jrdemail2000-dlang — 2019-02-17T09:24:40Z