Bug 19544 – Can't call inputRangeObject on ranges not supported by moveFront

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-01-03T14:16:48Z
Last change time
2021-10-05T09:33:03Z
Assigned to
No Owner
Creator
John Colvin

Comments

Comment #0 by john.loughran.colvin — 2019-01-03T14:16:48Z
e.g. with regex RegexMatch!string you get the error /usr/include/dlang/dmd/std/range/primitives.d(2023,9): Error: static assert: "Cannot move front of a range with a postblit and an rvalue front." /usr/include/dlang/dmd/std/range/interfaces.d(379,40): instantiated from here: moveFront!(RegexMatch!string) /usr/include/dlang/dmd/std/range/interfaces.d(488,1): instantiated from here: InputRangeObject!(RegexMatch!string) ../../lang/source/kaleidic/sil/lang/types.d(308,64): instantiated from here: inputRangeObject!(RegexMatch!string)
Comment #1 by Ajieskola — 2021-09-27T22:58:47Z
I have looked at this, and I'm afraid there is not much to do without a redesign. The root problem is that `InputRange` interface has the `moveFront` member, so ranges with postblitting rvalue elements simply do not satisfy the InputRange interface. This module is so old and stable that moving `moveFront` to `InputRangeAssignable` is too disruptive IMO. I see three reasonable courses of action: 1. Leave be as is, just document the behaviour. 2. Allow `moveFront` (here, but not at `std.range.primitives`) to call the postblit or copy constructor if it's the only way to access the front element. 3. Option 1 for now, but a redesign when the Phobos V2 versioning scheme is out. I think this warrants discussion. I'm going to start a forum thread tomorrow.
Comment #2 by Ajieskola — 2021-09-28T15:13:52Z
Forum theard here: https://forum.dlang.org/post/[email protected] A concrete test case: ---------- import std; struct HasCC { inout this(ref inout typeof(this)){} } void main() { auto iro = repeat(HasCC.init).inputRangeObject; } ----------
Comment #3 by dlang-bot — 2021-09-30T00:35:18Z
@pbackus created dlang/phobos pull request #8256 "Issue 19544 - Can't call inputRangeObject on ranges not supported by …" mentioning this issue: - Issue 19544 - Can't call inputRangeObject on ranges not supported by moveFront The range algorithms moveFront, moveBack, and moveAt do not accept all valid input ranges, bidirectional ranges, and random-access ranges, respectively. Their inclusion as methods of the InputRange, BidirectionalRange, and RandomAccessFinite interfaces previously caused InputRangeObject, which implements those interfaces, to fail to compile when instantiated with certain valid input, bidirectional, and random-access ranges. These methods should not have been included in their respective interfaces to begin with, but removing them now would break existing code. Instead, as a workaround, InputRangeObject now implements these methods by throwing an exception if the wrapped range does not support them. https://github.com/dlang/phobos/pull/8256
Comment #4 by dlang-bot — 2021-10-05T09:33:03Z
dlang/phobos pull request #8256 "Fix issue 19544 - Can't call inputRangeObject on ranges not supported by …" was merged into master: - d15e19fc44978424f57f05413d48666df635411d by Paul Backus: Fix issue 19544 - Can't call inputRangeObject on ranges not supported by moveFront The range algorithms moveFront, moveBack, and moveAt do not accept all valid input ranges, bidirectional ranges, and random-access ranges, respectively. Their inclusion as methods of the InputRange, BidirectionalRange, and RandomAccessFinite interfaces previously caused InputRangeObject, which implements those interfaces, to fail to compile when instantiated with certain valid input, bidirectional, and random-access ranges. These methods should not have been included in their respective interfaces to begin with, but removing them now would break existing code. Instead, as a workaround, InputRangeObject now implements these methods by throwing an exception if the wrapped range does not support them. https://github.com/dlang/phobos/pull/8256