Getter an lvalue and cannot be modified
Mike Franklin
slavo5150 at yahoo.com
Sun May 27 09:28:36 UTC 2018
On Sunday, 27 May 2018 at 09:23:09 UTC, IntegratedDimensions
wrote:
> C[] c;
> @property C[] get() { return c; }
>
> get ~= something;
>
> errors out, yet
>
> auto q = get;
> q ~= something;
>
> is fine.
>
>
> Why is D thinking that ~= is being applied to get, the
> function, rather than what it returns?
>
> Also
>
> When I converted a field in to a property, an AA, it is
> returning null rather than being initialized by default. Seems
> like properties are broke. I'd expect a property getter to
> behave, for all intents and purposes as if it were field. I
> shouldn't have to have a temp variable to be able to use it as
> such.
You'll probably get your answer and more by reading this:
https://github.com/dlang/DIPs/pull/97
TL;DR: return `ref C[]`
Mike
More information about the Digitalmars-d-learn
mailing list