https://issues.dlang.org/show_bug.cgi?id=22528
--- Comment #4 from Dennis <dkor...@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. --