[Issue 22916] New: [dip1000] copy of ref return still treated as scope variable
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Mar 24 11:10:00 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22916
Issue ID: 22916
Summary: [dip1000] copy of ref return still treated as scope
variable
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: safe
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dkorpel at live.nl
This came up in a custom dynamic array type of mine.
```
// compile with -preview=dip1000
@safe:
struct Arr
{
int** ptr;
ref int* index() return scope {
return *ptr;
}
void assign(int* p) scope {
*ptr = p;
}
}
void main()
{
scope Arr a;
a.assign(a.index());
}
```
`index` is `return scope` since it returns an element of a scope array by ref.
However, when it's passed to the `assign` function, a copy of the `ref` return
is passed, implicitly dereferencing it so it shouldn't be scope anymore. The
compiler still files this error though:
> Error: scope variable `a` assigned to non-scope parameter `p` calling onlineapp.Arr.assign
--
More information about the Digitalmars-d-bugs
mailing list