[Issue 23628] New: `@safe` prohibits capture if lazy delegate

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jan 15 01:38:57 UTC 2023


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 at puremagic.com
          Reporter: destructionator at 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
--


More information about the Digitalmars-d-bugs mailing list