[Issue 22528] [dip1000] scope inference turns return-ref into return-scope
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Nov 24 14:33:09 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22528
Dennis <dkorpel at live.nl> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dkorpel at live.nl
Hardware|x86_64 |All
Summary|Template breaks return |[dip1000] scope inference
|annotation for class |turns return-ref into
|reference returned by |return-scope
|struct method |
OS|Linux |All
--- Comment #1 from Dennis <dkorpel at live.nl> ---
What's happening is that `borrowA` gets `scope` inferred because it's a
template.
You can add this line to borrowA to break scope inference and make it behave
like borrowB:
```
inout D temp = this._target;
```
Here's a more reduced test case:
```
@safe:
struct S {
int* ptr;
auto borrowA() return {
return ptr;
}
int* borrowB() return /*scope inferred*/ {
return ptr;
}
}
void main() {
static int* global;
S s;
global = s.borrowA;
global = s.borrowB;
}
```
--
More information about the Digitalmars-d-bugs
mailing list