Thread overview
Do @property attributes not allow postincrement operators
Apr 14, 2019
Jamie
Apr 14, 2019
Mike Franklin
Apr 14, 2019
Jamie
April 14, 2019
Do @property attributes not allow postincrement operators?

import std.stdio;

struct Foo {
    @property bar() { return 10; }
    @property bar(int x) { writeln(x); }
}

void main()
{
    Foo foo;
    writeln(foo.bar); // actually calls foo.bar();
    foo.bar = 10; // calls foo.bar(10);

    // following doesn't work
    foo.bar++; // would expect this to call foo.bar(foo.bar() + 1);
    // have to use:
    foo.bar = foo.bar + 1;
    writeln(foo.bar);
}
April 14, 2019
On Sunday, 14 April 2019 at 01:54:39 UTC, Jamie wrote:
> Do @property attributes not allow postincrement operators?
>
> import std.stdio;
>
> struct Foo {
>     @property bar() { return 10; }
>     @property bar(int x) { writeln(x); }
> }
>
> void main()
> {
>     Foo foo;
>     writeln(foo.bar); // actually calls foo.bar();
>     foo.bar = 10; // calls foo.bar(10);
>
>     // following doesn't work
>     foo.bar++; // would expect this to call foo.bar(foo.bar() + 1);
>     // have to use:
>     foo.bar = foo.bar + 1;
>     writeln(foo.bar);
> }

It's a long standing issue (going on 7 years old)

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

There's an implementation at https://github.com/dlang/dmd/pull/7079

It requires a DIP, which you can find at https://github.com/dlang/DIPs/pull/97

However, in preparing that DIP other issues were discovered with @property, so we need to create a DIP to fix those issues first.

I plan on getting to it, but there are other pressing things I'm trying to get out of the way.

Mike
April 14, 2019
On Sunday, 14 April 2019 at 02:11:52 UTC, Mike Franklin wrote:
> On Sunday, 14 April 2019 at 01:54:39 UTC, Jamie wrote:
>> Do @property attributes not allow postincrement operators?
>> ...
>
> It's a long standing issue (going on 7 years old)
> ...
> I plan on getting to it, but there are other pressing things I'm trying to get out of the way.
>
> Mike

Thanks Mike -- appears I didn't do a thorough enough search for this behaviour. Looking forward to it being implemented, cheers.