Thread overview
[Issue 22284] [DIP1000] function templates cannot infer scope in instances with indirections when accessing the address of fields
Sep 07, 2021
João Lourenço
Sep 07, 2021
Dennis
Sep 07, 2021
João Lourenço
Sep 07, 2021
João Lourenço
Feb 13, 2022
Florian Weimer
Dec 17, 2022
Iain Buclaw
September 07, 2021
https://issues.dlang.org/show_bug.cgi?id=22284

João Lourenço <jlourenco5691@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jlourenco5691@gmail.com

--
September 07, 2021
https://issues.dlang.org/show_bug.cgi?id=22284

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dkorpel@live.nl
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #1 from Dennis <dkorpel@live.nl> ---
I'm not sure why your cannotInfer examples fail, 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`. The `scope` annotation of canInfer3 doesn't do anything since it's not a `delegate` but a `function` since you pass `this` explicitly through parameter `bar`.

--
September 07, 2021
https://issues.dlang.org/show_bug.cgi?id=22284

--- Comment #2 from João Lourenço <jlourenco5691@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;
}
```

--
September 07, 2021
https://issues.dlang.org/show_bug.cgi?id=22284

--- Comment #3 from João Lourenço <jlourenco5691@gmail.com> ---
I meant a delegate.

--
February 13, 2022
https://issues.dlang.org/show_bug.cgi?id=22284

Florian Weimer <fw@deneb.enyo.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fw@deneb.enyo.de

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=22284

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--