[Issue 14544] isForwardRange failed to recognise valid forward range

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon May 4 23:48:40 PDT 2015


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

Jacob Carlborg <doob at me.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |doob at me.com

--- Comment #5 from Jacob Carlborg <doob at me.com> ---
(In reply to Jonathan M Davis from comment #3)
> The problem is though that once
> it's required to be a property, changing it later risks breaking code. Given
> how poorly properties are checked by the compiler, we _might_ be able to
> make the change, but we'd have to be careful about it. Regardless, the fact
> that isForwardRange is the way it is and requires that save be a property is
> very much on purpose.

I'm not exactly sure how "is(typeof())" is working in this case but for a
getter, @property doesn't make a difference, regardless if compiled with the
-property flag. Take this code for example:

@property int foo ()
{
    return 1;
}

@property void bar (int a)
{
}

void main ()
{
    auto a = foo();
    auto b = foo;
    bar = 3;
    bar(4);
}

This code compiles both with and without the -property flag. The only thing
that will not compile is "bar = 3" if "bar" is _not_ marked with @property and
it's compiled with the -property flag.

What we can do what looks to be completely backwards compatible is modify the
"isForwardRange" constraint to look like this instead:

static assert (is(typeof(r1.save()) == R));

Or to make it more clear:

static assert (is(ReturnType!(save) == R));

These two will work regardless if @property is used on "save" or if the code is
compiled with -property.

--


More information about the Digitalmars-d-bugs mailing list