[Issue 6253] New: Refuse definition too of impossible associative arrays
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jul 5 10:44:33 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6253
Summary: Refuse definition too of impossible associative arrays
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Keywords: accepts-invalid
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2011-07-05 10:39:31 PDT ---
This program:
void main() {
bool[int[]] aa;
aa[[1, 2]] = true; // line 3
}
With DMD 2.053 gives a compile time-error:
test.d(3): Error: associative arrays can only be assigned values with immutable
keys, not int[]
While this program works:
import std.stdio;
void main() {
bool[int[]] aa;
aa[[1, 2].idup] = true;
foreach (k, v; aa)
writeln(typeid(typeof(k)), " ", typeid(typeof(v)));
}
With DMD 2.053 it prints:
const(int)[] bool
So the writeln shows that that the keys of the associative array aa are mutable
dynamic arrays of immutable integers. While the first program shows that the
compiler refuses to add a mutable dynamic array as key.
I think this is bad, and not intuitive. I suggest to make DMD refuse this
definition too:
bool[int[]] aa;
And accept this, and similar:
bool[const(int)[]] aa;
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list