Bug 2684 – Associative arrays have wrong opIndex signatures
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-02-22T09:47:00Z
Last change time
2015-06-09T05:14:39Z
Assigned to
bugzilla
Creator
andrei
Comments
Comment #0 by andrei — 2009-02-22T09:47:25Z
void main()
{
int[string] x;
char[] y;
if (y in x){}
int z = x[y];
}
The last two lines do not compile. However it makes of course sense to look up for a char[] or const(char)[] in a hash keyed by immutable(char)[]. Only the operator that inserts stuff into the hash should force the type immutable(char)[].
Bottom line: if the type of the key is K, any type K1 that allows comparison for equality and less-than with K should be accepted for lookup.