Did the implicit conversion from special slice expression to static array ever work?

Nick Treleaven nick at geany.org
Thu Sep 22 12:51:41 UTC 2022


On Thursday, 22 September 2022 at 12:48:18 UTC, Nick Treleaven 
wrote:
> On Thursday, 22 September 2022 at 10:50:28 UTC, Quirin Schroll 
> wrote:
>> ```d
>> int[] da = [1, 2, 3];
>> int i = da[0]; // runtime variable
>>
>> int[2] sa2 = da[i .. i + 2];
>> assert(sa2 == [2, 3]);
>>
>> // my tests
>> int[1] sa1 = da[i .. i + 2]; // core.exception.RangeError
>> int[3] sa3 = da[i .. i + 2]; // core.exception.RangeError
>> ```
> The problem is that you can initialize a static array from (or 
> assign to) a slice, even when the slice length is not 
> statically known.

Or rather *cannot be* statically known. I.e. `int[1] = da;` is 
allowed.


More information about the Digitalmars-d mailing list