Discussion Thread: DIP 1039--Static Arrays with Inferred Length--Community Review Round 1
Luhrel
lucien.perregaux at gmail.com
Thu Jan 7 15:58:24 UTC 2021
On Thursday, 7 January 2021 at 15:27:09 UTC, Dukc wrote:
> On Thursday, 7 January 2021 at 13:03:54 UTC, Luhrel wrote:
>> 2. if staticArrFunc returns a size_t, then the problem can be
>> simplified as:
>> ```
>> staticArrFunc(cast(int[$])[1,2,3]); // no need to cast :
>> staticArrFunc([1,2,3]); // already works like that (if
>> staticArrFunc takes a int[3])
>> ```
>
> If your DIP is implemented, what you say is true. But the point
> is that right now it means a different thing - a cast to static
> array of the length of `something` (in the full example), not
> to length of `[1,2,3]`. The point is that your DIP will
> silently change the behaviour of code like this.
I understand want do you mean, but we're currently unable to use
the `$` operation from `something` inside a cast.
```
int staticArrFunc(int[6] a)
{
return a[0];
}
void main()
{
int[] s = [1, 2, 3, 4, 5, 6];
int[] y = s[0 .. staticArrFunc(cast(int[$]) [1,2,3])];
// Error: CTFE internal error: trying to access uninitialized
var
}
```
Do you have a currently working example, that would potentially
be broken by my DIP ?
>
> I do agree that this is such a rare enough occurence that we
> might be best off just accepting it. But it needs to be
> mentioned in the DIP.
I don't want a DIP that will break other people codes.
More information about the Digitalmars-d-announce
mailing list