www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22916] New: [dip1000] copy of ref return still treated as


          Issue ID: 22916
           Summary: [dip1000] copy of ref return still treated as scope
           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
struct Arr
    int** ptr;

    ref int* index() return scope {
        return *ptr;

    void assign(int* p) scope {
        *ptr = p;

void main()
    scope Arr a;

`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
Mar 24 2022