[Issue 16763] Associative array literal inside array or AA literal doesn't work as initializer if variable type is known

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Dec 16 06:59:19 PST 2016


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

--- Comment #1 from Denis Shelomovskii <verylonglogin.reg at gmail.com> ---
(In reply to Denis Shelomovskii from comment #0)
>     int[int][] b = [[0 : 2]]; // expression ([[1]]) of type int[][]

It was "expression ([[2]])" actually.

So, looks like if `ArrayInitializer.inferType` isn't called AA literals are
treated as array literals with explicit indices (see Static Initialization of
Statically Allocated Arrays [1]) like in this code:
---
import std.stdio;

void main()
{
    int[][] a = [[2: 6, 1: 345, 3: 78, 6: 12]];
    writeln(a);
    int[][] aa = [1: [5: 7], 0: [7], 0: [0: 15] /* overrides previous element
0*/, [2: 6, 1: 3], /* overrides previous element 1*/ ]; 
    writeln(aa);
}
---
[[0, 345, 6, 78, 0, 0, 12]]
[[15], [0, 3, 6]]
---


[1] http://dlang.org/spec/arrays.html#static-init-static

--


More information about the Digitalmars-d-bugs mailing list