Implicit conversion of concatenation result to immutable

Steven Schveighoffer schveiguy at gmail.com
Thu Apr 1 22:34:04 UTC 2021


On 4/1/21 5:51 PM, Per Nordlöw wrote:
> On Thursday, 1 April 2021 at 21:41:06 UTC, Steven Schveighoffer wrote:
>> I'm surprised it doesn't return const(char)[].
> 
> I think it returning `char[]` is sound.

Not saying it's unsound, it just surprises me.

> What's unsound is that the compiler lacks knowledge of it being a unique 
> slice (no aliasing).

It shouldn't lack this knowledge. That's not soundness, it's just annoying.

I'm not saying I disagree with you, it's a limitation and I think 
there's no good explanation for the problem.

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
}
```

-Steve


More information about the Digitalmars-d mailing list