Do @property attributes not allow postincrement operators

Mike Franklin slavo5150 at yahoo.com
Sun Apr 14 02:11:52 UTC 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


More information about the Digitalmars-d-learn mailing list