Bug 24348 – Inaccurate documentation for hasSlicing with infinite range

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-01-20T22:14:14Z
Last change time
2024-01-20T23:53:15Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus

Comments

Comment #0 by snarwin+bugzilla — 2024-01-20T22:14:14Z
The documentation for std.range.hasSlicing states the following: > For infinite ranges, when not using opDollar, the result of opSlice must be > the result of take or takeExactly on the original range (they both return the > same type for infinite ranges). However, this is not true. The following program, which violates the above rule, compiles without errors: --- struct InfZeros { enum empty = false; int front() => 0; void popFront() {} auto save() => this; auto opIndex(size_t[2] bounds) { size_t i = bounds[0], j = bounds[1]; size_t length = i <= j ? j - i : 0; return Slice(length); } size_t[2] opSlice(size_t dim : 0)(size_t i, size_t j) => [i, j]; } struct Slice { size_t length; bool empty() => length == 0; int front() => 0; void popFront() { --length; } auto save() => this; } unittest { import std.range.primitives; static assert(hasSlicing!InfZeros); } ---
Comment #1 by dlang-bot — 2024-01-20T22:36:13Z
@pbackus created dlang/phobos pull request #8898 "Update docs for hasSlicing with inifnite range" fixing this issue: - Update docs for hasSlicing with inifnite range The requirement for opSlice on an infinite range to return the result of take or takeExactly was removed in commit c828a08b64, which was included in Phobos 2.067.0, released in March 2015. However, the documentation was never updated to take this change into account. This change updates the documentation and adds a unit test for the "new" behavior. Fixes bugzilla issue 24348. https://github.com/dlang/phobos/pull/8898
Comment #2 by dlang-bot — 2024-01-20T23:53:15Z
dlang/phobos pull request #8898 "Update docs for hasSlicing with inifnite range" was merged into master: - c00c9acf95a94faa40d53a62cf1f8565b887efee by Paul Backus: Update docs for hasSlicing with inifnite range The requirement for opSlice on an infinite range to return the result of take or takeExactly was removed in commit c828a08b64, which was included in Phobos 2.067.0, released in March 2015. However, the documentation was never updated to take this change into account. This change updates the documentation and adds a unit test for the "new" behavior. Fixes bugzilla issue 24348. https://github.com/dlang/phobos/pull/8898