DIP1000: 'return scope' ambiguity and why you can't make opIndex work
Dukc
ajieskola at gmail.com
Mon Jun 21 18:28:38 UTC 2021
On Monday, 21 June 2021 at 16:56:30 UTC, Dennis wrote:
> While ptr0 can be assigned to ptr1, when going through a
> `CustomPtr c`, dmd still sees it as assigning "scope variable
> `c`".
I was about to say it might be that you need to write
```d
void f(scope ubyte* ptr0) {
scope ubyte* ptr1;
ptr1 = ptr0; // fine
{
auto c = CustomPtr(ptr0);
ptr1 = c.get();with longer lifetime
}
}
```
...instead, but that fails too, at least on 2.096 release
canditate.
As does this one:
```d
ubyte* get(ref return scope ubyte* ptr){return ptr;}
void f(scope ubyte* ptr0) {
scope ubyte* ptr1;
ptr1 = ptr0; // fine
{
auto c = ptr0;
ptr1 = c.get();
}
}
```
I believe we can conclude that the field "`ref` argument / value
return / `scope`" already reads either "`ref`" or "both", at
least when you're returning a pointer. That being the case, your
solution makes perfect sense.
More information about the Digitalmars-d
mailing list