March 24, 2022 [Issue 22916] New: [dip1000] copy of ref return still treated as scope variable | ||||
|---|---|---|---|---|
| ||||
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@puremagic.com Reporter: dkorpel@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 -- | ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply