January 15, 2023 [Issue 23628] New: `@safe` prohibits capture if lazy delegate | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=23628 Issue ID: 23628 Summary: `@safe` prohibits capture if lazy delegate Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: rejects-valid Severity: normal Priority: P3 Component: dmd Assignee: nobody@puremagic.com Reporter: destructionator@gmail.com Depends on: 23627 ``` struct W { string delegate() magic; @safe void content(lazy string s) { magic = &s; } string test; } void main() { W w; w.content = w.test; } ``` lzy.d(5): Error: cannot take address of lazy parameter `s` in `@safe` function `content` The spec explicitly permits the taking of this address and since it is lowered to a delegate, the same rules should apply. I suspect this was added as a hack because the implementation incorrectly fails to generate a closure for lazy params: https://issues.dlang.org/show_bug.cgi?id=23627 But the spec says nothing of the sort. If I wanted a `scope lazy`, I would have written `scope lazy`. Referenced Issues: https://issues.dlang.org/show_bug.cgi?id=23627 [Issue 23627] lazy params don't allocateclosures -- |
Copyright © 1999-2021 by the D Language Foundation