Implicit conversion of concatenation result to immutable

Per Nordlöw per.nordlow at gmail.com
Thu Apr 1 21:51:22 UTC 2021


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.

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

The situation is analogous with

```d
alias T = int;
const n = 42;
auto x = new T[n]; // no conversion
static assert(is(typeof(x) == T[]));
immutable(T)[] y = new T[n]; // implicit conversion to immutable 
allowed
static assert(is(typeof(y) == immutable(T)[]));
```

which is currently accepted by the compiler.


More information about the Digitalmars-d mailing list