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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 26 02:01:48 UTC 2021


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

--- Comment #3 from thomas.bockman at gmail.com ---
(In reply to Dennis from comment #1)
> What's happening is that `borrowA` gets `scope` inferred because it's a
> template.

I don't get it. `return` restricts how the return value may be used by the
caller, and `scope` restricts how the `this` reference may be used by the
callee.

Why does an inferred restriction in once place effectively remove my explicit
restriction from another?

> You can add this line to borrowA to break scope inference and make it behave
> like borrowB:
> ```
> inout D temp = this._target;
> ```

Thanks for the workaround; I'll try that out.

It does look fragile though, as it's basically tricking the compiler. 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.

--


More information about the Digitalmars-d-bugs mailing list