Implicit conversion of concatenation result to immutable

Q. Schroll qs.il.paperinik at gmail.com
Thu Apr 1 23:11:34 UTC 2021


On Thursday, 1 April 2021 at 22:34:04 UTC, Steven Schveighoffer 
wrote:
> To illustrate the point more cleanly:
>
> ```d
> auto concat(T, U)(T[] x, U[] y) pure
> {
>     return x ~ y;
> }
>
> void main()
> {
>     string x;
>     const(char)[] y;
>     string z = concat(x, y); // compiles
> }
> ```

Found by accident that the code does not compile with -dip1000 on 
2.095 (run.dlang.org).

Actually, I tried inclining the function template and to my 
surprise, whether it passes or not depends on -dip1000:
```D
     string z1 = (() => x ~ y)(); // fails with and without 
-dip1000
     string z2 = ((x, y) => x ~ y)(x, y); // passes without, fails 
with -dip1000
```

It makes no difference adding `pure` to any of those since it's 
inferred.


More information about the Digitalmars-d mailing list