www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21286] New: [DIP1000] Can't return scope reference from a


          Issue ID: 21286
           Summary: [DIP1000] Can't return scope reference from a function
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: snarwin+bugzilla gmail.com

The following program fails to compile with -preview=dip1000:

void main()  safe
    int[3] a = [1, 2, 3];
    int[] slice;

    // ok
    slice = a[];

    scope ref getSlice() { return slice; }
    // Error: reference to local variable a assigned to non-scope getSlice()
    getSlice() = a[];

It should be possible for getSlice to return a reference that `a[]` can be
safely assigned to.

Sep 30 2020