Thread overview
[Issue 18827] scope delegate literal allocates GC closure
May 04, 2018
Shachar Shemesh
Jun 02, 2021
Dennis
May 04, 2018
https://issues.dlang.org/show_bug.cgi?id=18827

Shachar Shemesh <shachar@weka.io> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |shachar@weka.io

--
May 13, 2018
https://issues.dlang.org/show_bug.cgi?id=18827

johanengelen@weka.io changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |industry
                 CC|                            |johanengelen@weka.io

--
June 02, 2021
https://issues.dlang.org/show_bug.cgi?id=18827

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |dkorpel@live.nl
         Resolution|---                         |INVALID

--- Comment #1 from Dennis <dkorpel@live.nl> ---
It should allocate a closure, since `func` is free to escape the delegate,
e.g.:
```
int delegate(int) global;

int func(int delegate(int) dg)
{
    global = dg;
    return dg(2);
}

void bar()
{
    int a = 3;
    scope dg = (int x) => x * a;
    func(dg); // passing scope dg to non-scope parameter makes bar @system
    func((int x) scope => x * a);
}
```

When marking the input delegate of `func` `scope`, it works:
```
@safe:
int func(scope int delegate(int) @safe @nogc dg) @nogc
{
    return dg(2);
}

void bar() @nogc
{
    int a = 3;
    scope dg = (int x) => x * a;
    func(dg);
    func((int x) scope => x * a);
}
```

--