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

Dukc ajieskola at gmail.com
Sat Jun 19 14:39:01 UTC 2021


On Saturday, 19 June 2021 at 09:43:18 UTC, ag0aep6g wrote:
> A quick and easy fix could be introducing `return(ref)` and 
> `return(scope)`, allowing the programmer to pick what `return` 
> binds to. Then `opIndex` can be written this way:
>
> ----
> ref float opIndex(size_t i) return(scope) {
>     return this._elements[i];
> }
> ----
>

No thanks. The compiler still has ambiguity between

```d
ref float opIndex(return(scope) ref __this, size_t i);
return(scope) ref float opIndex(ref __this, size_t i);
```

It's simpler and better if `return` attribute outside the 
parameter list always binds to `this`. Unless there is some 
reason you might want to annotate the return type as `return`? I 
can't think of any.

> I'm afraid DIPs 25 and 1000 are falling short.

In the sense that you can't have deep `scope`, true. But I think 
DIP1000 was deliberately designed to not address that, for 
simplicity. I suggest that we leave fixing that for a potential 
future DIP.

Just by fixing that `opIndex` example we still have the ability 
to define custom types that can be used for deep lifetime 
checking.



More information about the Digitalmars-d mailing list