Bug 24342 – T[][].until(T[]) breaks if sentinel is longer than 1.

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2024-01-17T13:12:08Z
Last change time
2024-01-28T01:26:52Z
Keywords
pull
Assigned to
No Owner
Creator
FeepingCreature

Comments

Comment #0 by default_357-line — 2024-01-17T13:12:08Z
import std; void main() { int[] marker = [2, 3]; int[][] first = [[1], [2, 3], [4]]; int[][] second = first.until(marker, No.openRight).array; assert(second == [[1], [2, 3]]); } Instead, `second` is [[1], [2, 3], [4]]. This happens because `until` does not differentiate "range is T[] and sentinel is T[]" from "range is _T[][]_ and sentinel is T[]". This leads it to advance two rather than one elements if the sentinel is two long.
Comment #1 by dlang-bot — 2024-01-17T13:42:06Z
@FeepingCreature updated dlang/phobos pull request #8894 "Fix issue 24342: Actually check that range and sentinel types match" fixing this issue: - Fix Bugzilla issue 24342: Actually check that range and sentinel types match in `until` before using "sentinel as subrange" mode. `until` does special magic when `Sentinel` consists of multiple elements of `Range`. However, because `Range` can be a range of ranges, in which case even a `Sentinel` that is a range may still only be a single element, we must confirm that the element type of `Sentinel` is actually the same as `Range` before enabling this. The `immutable ElementEncodingType` idiom is stolen from `startsWith`, which forms the basis of `until` anyways (see `predSatisfied`). https://github.com/dlang/phobos/pull/8894
Comment #2 by dlang-bot — 2024-01-18T06:57:01Z
dlang/phobos pull request #8894 "Fix issue 24342: Actually check that range and sentinel types match" was merged into stable: - 232d4784c017ae94694f1f0edbef45d7494026ec by Mathis Beer: Fix Bugzilla issue 24342: Actually check that range and sentinel types match in `until` before using "sentinel as subrange" mode. `until` does special magic when `Sentinel` consists of multiple elements of `Range`. However, because `Range` can be a range of ranges, in which case even a `Sentinel` that is a range may still only be a single element, we must confirm that the element type of `Sentinel` is actually the same as `Range` before enabling this. The `immutable ElementEncodingType` idiom is stolen from `startsWith`, which forms the basis of `until` anyways (see `predSatisfied`). https://github.com/dlang/phobos/pull/8894
Comment #3 by dlang-bot — 2024-01-28T01:26:52Z
dlang/phobos pull request #8905 "merge stable" was merged into master: - 5976fe8c1ac4aeca87642683494b50eed5f3b2c9 by Mathis Beer: Fix Bugzilla issue 24342: Actually check that range and sentinel types match in `until` before using "sentinel as subrange" mode. `until` does special magic when `Sentinel` consists of multiple elements of `Range`. However, because `Range` can be a range of ranges, in which case even a `Sentinel` that is a range may still only be a single element, we must confirm that the element type of `Sentinel` is actually the same as `Range` before enabling this. The `immutable ElementEncodingType` idiom is stolen from `startsWith`, which forms the basis of `until` anyways (see `predSatisfied`). https://github.com/dlang/phobos/pull/8905