[Issue 23294] New: [dip1000] parameter to parameter assignment leads to incorrect scope inference

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 15 12:51:41 UTC 2022


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

          Issue ID: 23294
           Summary: [dip1000] parameter to parameter assignment leads to
                    incorrect scope inference
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: safe
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dkorpel at live.nl

x and y are inferred scope in the following example:
```
@safe:
int global;

auto f(int* x, int* y)
{
    x = y;
    global++; // make sure it's not inferring scope from pure
}

void g(scope int* z)
{
    f(z, z); // passes
}
```

When you mark `x` and `y` as `scope` explicitly, it errors:

> Error: scope variable `y` assigned to `x` with longer lifetime

But evidently, scope parameter inference does not care about relative lifetime
of parameters, which is problematic when they have destructors.

--


More information about the Digitalmars-d-bugs mailing list