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

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Feb 4 01:21:52 UTC 2019


On 2/1/19 8:15 PM, 12345swordy wrote:
> 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.

Such would be a good conservative approach for us too. We can relax it 
later if we come with a good idea.


More information about the Digitalmars-d-announce mailing list