DIP1000: 'return scope' ambiguity and why you can't make opIndex work

Walter Bright newshound2 at digitalmars.com
Tue Jul 6 09:37:30 UTC 2021


On 7/6/2021 2:23 AM, Dennis wrote:
> On Tuesday, 6 July 2021 at 05:15:24 UTC, Walter Bright wrote:
>> This rule is arbitrary, precluding things like creating a `return ref` and
>> `return scope` for the same parameter.
> 
> My question is: why? Why can't we allow a ref parameter to return either its 
> address or its value? Given that lifetime(address) <= lifetime(value) and the 
> returned value has lifetime(address), I'm struggling to see where it goes wrong.

It doesn't make sense to return either p or the address of p with the same 
function. What kind of a function does that? We could trick the code into doing 
that, but that would introduce all kinds of bugs into the lifetime analysis code.

The real problem is not being able to return the value of p as a ref, if p is 
also passed by ref.

I'm going to look into addressing that.


More information about the Digitalmars-d mailing list