[Issue 20009] New: isForwardRange doesn't work with alias range this or inheritance

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 27 21:24:42 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=20009

          Issue ID: 20009
           Summary: isForwardRange doesn't work with alias range this or
                    inheritance
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: ali.akhtarzada at gmail.com

struct FR {
  bool empty = true;
  void popFront() {}
  auto front() { return 0; }
  FR save() { return this; }
}

struct S {
  FR range;
  alias range this;
}

pragma(msg, isInputRange!S); // true
pragma(msg, isForwardRange!S); // false

It's because isForwardRange is defined as:

isInputRange!R && is(ReturnType!((R r) => r.save) == R);

But it should be:

isInputRange!R && is(R : ReturnType!((R r) => r.save));

The same thing will happen if you try an inherit from an interface that is a
forward range, and if the save function returns the base class it will fail.

--


More information about the Digitalmars-d-bugs mailing list