[Issue 19681] New: std.range.padRight.popFront does not correctly adjust length

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 16 20:55:34 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19681

          Issue ID: 19681
           Summary: std.range.padRight.popFront does not correctly adjust
                    length
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: jrdemail2000-dlang at yahoo.com

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.

--


More information about the Digitalmars-d-bugs mailing list