[Issue 21912] Invalid stack closure when calling delegate inside lambda

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat May 15 13:58:30 UTC 2021


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

Dennis <dkorpel at live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|DUPLICATE                   |---

--- Comment #8 from Dennis <dkorpel at live.nl> ---
(In reply to Sebastiaan Koppe from comment #7)
> If this has to do with "pure bypassing scope checks", then making one of the
> above examples un-pure would solve it. Although it does work with your
> reduced case, not with the ones where foo has a DG template parameter.

You're right, it turns out there is another issue at play. Reduced to explicit
attributes:

```
int delegate() foo(return int delegate() dg) {
    return dg;
}

int delegate() bla(int i) {    
    return foo(() => i);
}

void main() {
    assert(bla(5)() == 5);
}
```

Since () => i is assigned to a `return` parameter, the expression `foo(() =>
i)` should be `scope` and cannot be returned from `bla` without allocating a
closure with i on the heap.

I quickly looked at the existing dip1000 issues but couldn't find something
similar enough, so let's re-open it.

--


More information about the Digitalmars-d-bugs mailing list