[Issue 18827] scope delegate literal allocates GC closure
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jun 2 14:04:28 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=18827
Dennis <dkorpel at live.nl> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |dkorpel at live.nl
Resolution|--- |INVALID
--- Comment #1 from Dennis <dkorpel at 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);
}
```
--
More information about the Digitalmars-d-bugs
mailing list