[Issue 23216] New: Better Error Message For foreach_reverse Without Bidirectional Range
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Mon Jun 27 17:30:21 UTC 2022
    
    
  
https://issues.dlang.org/show_bug.cgi?id=23216
          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 at puremagic.com
          Reporter: jack at 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("||"))
        writeln(word);
}
```
Gives:
```
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"
--
    
    
More information about the Digitalmars-d-bugs
mailing list