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: [email protected]
          Reporter: [email protected]

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.

--

Reply via email to