October 29, 2023
https://issues.dlang.org/show_bug.cgi?id=24208

          Issue ID: 24208
           Summary: [DIP1000] Nested function can pass scope pointer to
                    non-scope parameter
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: snarwin+bugzilla@gmail.com

As of DMD 2.105.2, the following invalid program compiles with -preview=dip1000 and runs without errors:

---
void main() @safe
{
    int* escaped;

    void escape(int* p) @safe
    {
        escaped = p;
    }
    void borrow(scope int* param) @safe
    {
        escape(param);
    }

    int n;
    borrow(&n);
    assert(escaped == &n);
}
---

This program is invalid because, in @safe code, it assigns the address of the variable `n` to the variable `escaped`, which has a longer lifetime than `n`.

The expression `escape(param)` should cause a compile-time error, because it assigns the value of the scope parameter `param` to the non-scope parameter `p`.

--