Bug 6469 – Compiler fails to initialize associative array: string->[string->string]

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-08-11T14:14:37Z
Last change time
2024-12-13T17:55:58Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Blazej Podsiadlo
Moved to GitHub: dmd#18360 →

Attachments

IDFilenameSummaryContent-TypeSize
1015main.dsourceCodeapplication/octet-stream579

Comments

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. ***
Comment #7 by k.hara.pg — 2014-06-19T04:56:13Z
Comment #8 by k.hara.pg — 2015-09-01T12:44:37Z
*** Issue 14977 has been marked as a duplicate of this issue. ***
Comment #9 by robert.schadek — 2024-12-13T17:55:58Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18360 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB