Comment #0 by blazej.podsiadlo — 2011-08-11T14:14:37Z
Hi,
I'm not able to compile following code:
import std.stdio;
// print string->[string->string]
void printer(ref string[string][string] input) {
foreach (k, ref v; input) {
writeln(k,":");
foreach (ki, vi ; v) {
writeln("\t", ki, "->", vi);
}
}
}
int main()
{
writeln();
alias string[string][string] sss;
// works fine
sss dyn;
dyn["one"] = ["a":"A", "b":"B"];
dyn["two"] = ["c":"C", "d":"D"];
printer(dyn);
// fails during compilation
sss stat = [
"one" : ["a":"A", "b":"B"],
"two" : ["d":"D", "e":"E"],
];
printer(stat);
return 0;
}
----------
/Users/blazej/Projekty/D/bpodProject/bpTable/main.d(30): Error: Integer constant expression expected instead of "a"
/Users/blazej/Projekty/D/bpodProject/bpTable/main.d(30): Error: Integer constant expression expected instead of "b"
/Users/blazej/Projekty/D/bpodProject/bpTable/main.d(30): Error: Integer constant expression expected instead of "a"
/Users/blazej/Projekty/D/bpodProject/bpTable/main.d(30): Error: Integer constant expression expected instead of "b"
/Users/blazej/Projekty/D/bpodProject/bpTable/main.d(28): Error: not an associative array initializer
make[2]: *** [bpTable/CMakeFiles/bpTable.dir/main.o] Error 1
make[1]: *** [bpTable/CMakeFiles/bpTable.dir/all] Error 2
make: *** [all] Error 2
----------
Best Regards,
Blazej
Comment #1 by blazej.podsiadlo — 2011-08-11T14:16:07Z
Created attachment 1015
sourceCode
Comment #2 by andrej.mitrovich — 2012-03-22T22:14:30Z
As I've just discovered, you can use a cast() as a workaround until this gets fixed:
sss stat = cast()[
"one" : ["a":"A", "b":"B"],
"two" : ["d":"D", "e":"E"],
];
Comment #3 by lovelydear — 2012-04-20T16:03:35Z
Also fails on 2.059 Win32.
Comment #4 by bearophile_hugs — 2013-09-03T04:44:41Z
DMD 2.064alpha gives:
void main() {
int[int] aa1 = [10: 1, 20: 2]; // OK
int[int][int] aa2 = [30: aa1]; // OK
int[int][int] aa3 = cast()[30: [10: 1, 20: 2]]; // Error.
}
test.d(4): Error: not an associative array initializer
Comment #5 by k.hara.pg — 2014-06-19T04:19:26Z
*** Issue 9520 has been marked as a duplicate of this issue. ***
Comment #6 by k.hara.pg — 2014-06-19T04:19:35Z
*** Issue 12787 has been marked as a duplicate of this issue. ***