[Issue 22528] [dip1000] scope inference turns return-ref into return-scope

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 26 09:48:40 UTC 2021


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

--- Comment #4 from Dennis <dkorpel at live.nl> ---
(In reply to thomas.bockman from comment #3)
> Why does an inferred restriction in once place effectively remove my
> explicit restriction from another?

Because the implementation is bad, it currently has flags STC.scope_ and
STC.return_ and infers the meaning of STC.return from context. Walter is
working on using STC.returnScope instead, see issue 22541 and
https://github.com/dlang/dmd/pull/13357

> At any
> time the compiler could be upgraded to be smart enough to recognize that
> this line is, in context, a no-op and can be ignored for analysis purposes.

Yes, it relies on issue 20674. I do think this issue will be solved before
that, but you could also add a unittest with `assert(!__traits(compiles, ()
@safe {...}));` to test that escaping a reference isn't allowed, so you'll be
aware when the workaround breaks.

--


More information about the Digitalmars-d-bugs mailing list