www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17661] New: New isInputRange rejects valid input range


          Issue ID: 17661
           Summary: New isInputRange rejects valid input range
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: hsteoh quickfur.ath.cx

Code (compile with -dip25 -dip1000):

import std.range.primitives;
struct C {
    private S* impl;
struct S {
    bool empty;
     property C front() return { return C(&this); }
    void popFront() { }

    static assert(isInputRange!S); // FAILS

Prior to git commit 82c3371d85154b7f98b1c9187b79805a50fc59dd, the assert
passes. However, the new isInputRange checks introduced by this commit causes
the above breakage.

The problem is the new clause `typeof((R r) => r.front` in the new
isInputRange. Because S.front returns a reference to `this` it carries the
`return` annotation, so the compiler does not reject `front`. However, the
check in isInputRange does not have this annotation, so the compiler rejects it
as escaping a reference to `this`, thus causing isInputRange to fail to
recognize S as an input range.

Jul 17 2017