Bug 23628 – `@safe` prohibits capture of lazy delegate

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-01-15T01:38:57Z
Last change time
2024-12-13T19:26:40Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Adam D. Ruppe
Depends on
23627
Moved to GitHub: dmd#18146 →

Comments

Comment #0 by destructionator — 2023-01-15T01:38:57Z
``` 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`.
Comment #1 by robert.schadek — 2024-12-13T19:26:40Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18146 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB