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.
Comment #3 by k.hara.pg — 2014-04-21T02:41:46Z
Comment #4 by github-bugzilla — 2014-04-21T15:20:01Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/85700f9e05a229f2f810f4a5a662d0b6aaed4d5e fix Issue 12593 - AA cannot have struct as key https://github.com/D-Programming-Language/dmd/commit/4cd94f6104e3690add8fa786d4c386eae3c77184 Merge pull request #3476 from 9rnsr/fix12593 [REG2.065] Issue 12593 - AA cannot have struct as key