Thread overview
[Issue 24370] static array values in static AA initialise to dynamic arrays
Feb 06
Dlang Bot
Feb 06
Dlang Bot
Feb 16
Dlang Bot
February 04
https://issues.dlang.org/show_bug.cgi?id=24370

--- Comment #1 from zxinsworld@gmail.com ---
Correction: this also applies to the initial value of mutable module-level associative arrays.

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

Steven Schveighoffer <schveiguy@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@gmail.com

--- Comment #2 from Steven Schveighoffer <schveiguy@gmail.com> ---
If I put a pragma(msg, V) inside the `core.internal.newaa.makeAA` template,
it's printing out:

immutable(uint)[]

which explains why it's not working. Something in the way the lowering is done doesn't work correctly.

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

--- Comment #3 from Steven Schveighoffer <schveiguy@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.

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

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
@dkorpel created dlang/dmd pull request #16164 "Fix Bugzilla Issue 24370 - static array values in static AA initialis…" fixing this issue:

- Fix Bugzilla Issue 24370 - static array values in static AA initialise to dynamic arrays

https://github.com/dlang/dmd/pull/16164

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

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #16164 "Fix Bugzilla Issue 24370 - static array values in static AA initialis…" was merged into stable:

- 8056c9a8aa9c1303486e9f91d4b8c1b38b2ba3e4 by Dennis Korpel:
  Fix Bugzilla Issue 24370 - static array values in static AA initialise to
dynamic arrays

https://github.com/dlang/dmd/pull/16164

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

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #16195 "merge stable" was merged into master:

- aa122ae00018a2240b39efe53221b731a6db6634 by Dennis Korpel:
  Fix Bugzilla Issue 24370 - static array values in static AA initialise to
dynamic arrays

https://github.com/dlang/dmd/pull/16195

--