[Issue 21286] [DIP1000] Can't return scope reference from a function
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Nov 17 21:57:17 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=21286
Dennis <dkorpel at live.nl> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dkorpel at live.nl
Hardware|x86_64 |All
OS|Linux |All
--- Comment #4 from Dennis <dkorpel at live.nl> ---
I think the problem there is that it doesn't consider `getRef(p)` to be
variable `p`. While the right hand side of an = uses
`escapeByValue/escapeByRef` logic, the left hand side uses `expToVariable`,
which can only return one variable, so it gives up on potential
multiple-variable expressions. For example:
```D
void main() @safe
{
int n;
scope int* p;
(n ? p : p) = &n;
}
```
Error: reference to local variable `n` assigned to non-scope `*(n ? & p : & p)`
I think this could be fixed by using the same escapeByValue logic for the lhs
and repeating the rest of the checkAssignEscape logic for all possible lhs
variables. It won't have the best time complexity, but complex lhs expressions
should be rare.
--
More information about the Digitalmars-d-bugs
mailing list