Implicit conversion of concatenation result to immutable
Per Nordlöw
per.nordlow at gmail.com
Thu Apr 1 22:07:26 UTC 2021
On Thursday, 1 April 2021 at 21:21:02 UTC, Per Nordlöw wrote:
> Can somebody explain the logic behind the compiler disallowing
> both line 3 and 4 in
I'm very intrigued by the fact the this issue hasn't been
discussed more. It smells to me like this behaviour is somewhat
by design...because I don't think it is at all difficult to fix.
During implicit conversion checking, just peek into the
expression and see if it's CatExp and if so treat it as a unique
reference and allow conversion from mutable non-mutable.
However, note that to solve this in the general case we have to
involve data flow and escap e analysis. And have a tag associated
with a variable that indicates whether it is aliased or not (on,
yes, maybe).
Consider, for instance,
```d
auto c = a ~ b;
e = d; // `d` aliased to `e`
f = foo(e); // `e` maybe aliased to `f`
immutable g = e; // allowed?
```
More information about the Digitalmars-d
mailing list