Bug 12593 – [REG2.065] AA cannot have struct as key
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-04-18T11:22:00Z
Last change time
2014-04-21T15:20:02Z
Keywords
rejects-valid
Assigned to
nobody
Creator
yazan.dabain
Comments
Comment #0 by yazan.dabain — 2014-04-18T11:22:06Z
Code:
int[R] aa;
struct R {}
void main() {}
Compiler output:
test.d(1): Error: associative array key type R does not have 'const int opCmp(ref const R)' member function
which is understandable. However, let's add the missing member function.
Code:
int[R] aa;
struct R {
const int opCmp(ref const R) { return 0; }
}
void main() {}
Compiler output:
test.d(1): Error: associative array key type R does not have 'const int opCmp(ref const R)' member function
We still have the same error although the member function exists! I tried adding opEquals and toHash functions too, but I get the same output.
Now let's try the following:
Code:
import std.array; // can be other modules also (e.g. range, algorithm, string, format) but not all modules enable this code to compile (e.g. typetuple)
int[R] aa;
struct R {}
void main() {}
Now with having some arbitrary import, the code compiles! Although opCmp is missing.
Comment #1 by dlang-bugzilla — 2014-04-19T10:26:40Z
Duplicate of issue 12255?
Comment #2 by yazan.dabain — 2014-04-20T12:38:42Z
It is related, but I couldn't get it to work even with opCmp/opEquals/toHash or different combinations of them. So this is a more general issue.