www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23073] New: [dip1000] scope inference from pure doesn't

https://issues.dlang.org/show_bug.cgi?id=23073

          Issue ID: 23073
           Summary: [dip1000] scope inference from pure doesn't consider
                    self-assignment
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dkorpel live.nl

```
 safe:

class C 
{
    C next;
}

void assignNext(C c) pure nothrow  nogc 
{
    c.next = c;
}

C escape()  nogc
{
    scope C c = new C();
    assignNext(c);
    return c.next;
}

void main()
{
    C dangling = escape();
}

```

`assignNext` should not be callable on a `scope` parameter. The compiler sees
no other parameters that c could be assigned to, but doesn't consider that
mutable aggregates may have extra pointer layers, allowing you to escape a
scope pointer because of the lack of transitive scope.

--
Apr 30 2022