DIP 1016--ref T accepts r-values--Formal Assessment

12345swordy alexanderheistermann at gmail.com
Sat Feb 2 01:15:54 UTC 2019


On Friday, 1 February 2019 at 23:24:44 UTC, Olivier FAURE wrote:
> On Friday, 1 February 2019 at 09:10:15 UTC, aliak wrote:
>> Shouldn't doubleMyValue(pt.x) be a compiler error if pt.x is a 
>> getter? For it not to be a compile error pt.x should also have 
>> a setter, in which case the code needs to be lowered to 
>> something else:
>
> The thing is, D doesn't really differentiate between a getter 
> and any other method.
>
> So with DIP-1016, when given
>
>     doubleMyValue(pt.x);
>
> The compiler would assume the programmer means
> - Call pt.x()
> - Store the result in a temporary
> - Pass that temporary as a ref parameter to doubleMyValue
>
> At no point is the compiler aware that the user intends for x 
> to be interpreted as a getter.

Languages like c# solve this problem by disallowing passing 
property to ref parameter arguments.


More information about the Digitalmars-d-announce mailing list