[Issue 22284] [DIP1000] function templates cannot infer scope in instances with indirections when accessing the address of fields

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 7 17:12:23 UTC 2021


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

--- Comment #2 from João Lourenço <jlourenco5691 at gmail.com> ---
Yes the last 2 make sense to infer scope, the comments were because I'm
specifying other templates with `(this This)` and they cannot infer scope.

> but canInfer3 and canInfer4 succeed because the parameter (This bar) in the lambda is inferred scope since it's passed by value and the lambda is `pure` and returns `void`, so it can't escape `arr`.

Ok, but I can make it a function and still escape its context:

```
@safe:

struct Bar
{
    void canInfer(this This)()
    {
        This other;
        (This bar) { other = bar; } (this);
        with(other) cast(void) &i; 
    }

    int[] arr = [0];
    int i;
}

void main()
{
    scope bar = Bar();
        bar.canInfer;
}
```

--


More information about the Digitalmars-d-bugs mailing list