[Issue 24370] static array values in static AA initialise to dynamic arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 6 20:28:24 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24370

--- Comment #3 from Steven Schveighoffer <schveiguy at gmail.com> ---
At runtime, the compiler changes this:

uint[3][string] x = ["hello": [1, 2, 3];

into:

uint[3][string] x = ["hello": [1u, 2u, 3u]]

Note the `u` suffixes, which the compiler adds when seeing the type is `uint`.

This is fine, because the expression has no specific type, just the values have
types that are inferred. And the semantic knows how to process this.

However, what we are doing is effectively:

uint[3][string] x = cast(void*)__aaAsStruct(["hello": [1u, 2u, 3u]])

This *leaves out* the type inference based on the type assignment, and uses
IFTI to infer the K and V parameters passed to __aaAsStruct without the context
of x.

What we need to do is __aaAsStruct(cast(typeof(x))["hello": [1u, 2u, 3u]]) so
it will infer the types needed. I'm not 100% sure this will work, because
casting is weird at compile-time.

Alternatively, it could explicitly intstantiate e.g. __aaAsStruct!(string,
uint[3])(...)

This is slightly less desirable, since it assumes the compile-time parameters
of the hook. It also might have issues which are solved quite easily using
IFTI.

--


More information about the Digitalmars-d-bugs mailing list