www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23216] New: Better Error Message For foreach_reverse Without


          Issue ID: 23216
           Summary: Better Error Message For foreach_reverse Without
                    Bidirectional Range
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: jack jackstouffer.com

When a range is given to foreach_reverse, but it doesn't have back and popBack,
DMD gives a confusing error message.

import std.algorithm;
import std.stdio;

void main()
    string a = "This||is||a||test!";
    foreach_reverse (word; a.splitter("||"))


Error: invalid `foreach` aggregate `splitter(a, "||")`, define `opApply()`,
range primitives, or use `.tupleof`

Expected Behavior:

DMD should detect that the given value is an input range print something like

"Error: Input range splitter(a, "||") passed as foreach aggregate.
foreach_reverse requires a bidirectional range"

Jun 27 2022