Timon Gehr 
Posted in reply to Nick Treleaven
| On 5/15/25 17:32, Nick Treleaven wrote:
> On Wednesday, 14 May 2025 at 17:00:02 UTC, Timon Gehr wrote:
>> On 5/13/25 22:19, Meta wrote:
>>> On Tuesday, 13 May 2025 at 07:25:06 UTC, Sergey wrote:
>>>> Just to clarify, will the static arrays gonna work?
>>>> ```d
>>>> (int a, float[3] b, string c) = tuple(1, 0.1, 0.2, 0.3, "2");
>>>> ```
>>>
>>> I'm pretty sure that works, except it should be [0.1, 0.2, 0.3].
>>
>> Has to be `[0.1, 0.2, 0.3].staticArray` actually, as there is no reverse type inference on IFTI.
>
> Either of these seem to work with the unpacking branch:
> ```d
> (int a, float[3] b, string c) = tuple(1, [0.1F, 0.2F, 0.3F], "2");
> (int a, double[3] b, string c) = tuple(1, [0.1, 0.2, 0.3], "2");
> ```
>
You are correct. I did not take into account that this works:
```d
void main(){
int[] x=[1,2,3];
int[3] y=x;
}
```
(I would actually prefer if this did not work.)
It is not a great way to do it:
```d
import std.typecons;
void main()@nogc{
(int a, float[3] b, string c) = tuple(1, [0.1F, 0.2F, 0.3F], "2"); // compile error
}
```
```d
import std.typecons;
void main(){
(int a, float[3] b, string c) = tuple(1, [0.1F, 0.2F, 0.3F, 0.4F], "2"); // runtime error
}
```
Compare to:
```d
import std.typecons, std.array;
void main()@nogc{
(int a, float[3] b, string c) = tuple(1, [0.1F, 0.2F, 0.3F].staticArray, "2"); // ok
}
```
```d
import std.typecons, std.array;
void main()@nogc{
(int a, float[3] b, string c) = tuple(1, [0.1F, 0.2F, 0.3F, 0.4F].staticArray, "2"); // compile error
}
```
|