Bug 11591 – std.typecons.Tuple -s with classes fails at runtime as associative array keys

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-24T00:46:00Z
Last change time
2017-07-05T20:30:14Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
verylonglogin.reg
See also
https://issues.dlang.org/show_bug.cgi?id=4290

Comments

Comment #0 by verylonglogin.reg — 2013-11-24T00:46:59Z
At least a year ago `const`/`immutable` `std.typecons.Tuple`-s with classes worked as associative array keys. The fact it fails at runtime now is rather nasty. It should either work or fail to compile. --- import std.typecons; void main() { alias T = Tuple!Object; int[const T] aa; // No CT errors aa[T()] = 1; aa[T()] = 1; // Error at runtime } --- object.Error: TypeInfo.compare is not implemented --- E.g. fixing Issue 11590 will fix this issue by rejecting such associative arrays to compile unless Issue 1824 is fixed.
Comment #1 by verylonglogin.reg — 2013-11-24T01:33:08Z
Sorry, original comment is wrong. The regression is for unqualified tuples: --- import std.typecons; void main() { alias T = Tuple!Object; int[T] aa; // No CT errors aa[T()] = 1; aa[T()] = 1; // Error at runtime } ---
Comment #2 by bugzilla — 2013-12-31T14:22:05Z
This comes about because std.typecons.Tuple generates a struct but does not generate an opCmp operator overload function for it. Actually, it does build an opCmp, but as a template, whereas in clone.c buildXopCmp() looks for a function named opCmp, not a template.
Comment #3 by verylonglogin.reg — 2013-12-31T14:53:25Z
(In reply to comment #2) > This comes about because std.typecons.Tuple generates a struct but does not > generate an opCmp operator overload function for it. Actually, it does build an > opCmp, but as a template, whereas in clone.c buildXopCmp() looks for a function > named opCmp, not a template. Actually there is no problem with the fact it's a template here IIRC. The problem is the template (a `const` overload) can't be instantiated.
Comment #4 by bugzilla — 2013-12-31T18:53:04Z
I did some more digging on this. The fundamental problem is that for AA's to work, then opCmp() has to work. opCmp needs an ordering, a "<" operation. But there is no defined ordering for Object. Hence, it fails. I don't see how const makes any difference. Nor is this really about Tuples, it's about using Object as a key for an associative array.
Comment #5 by bugzilla — 2013-12-31T21:20:55Z
Comment #6 by bugzilla — 2014-01-01T02:46:09Z
*** Issue 11590 has been marked as a duplicate of this issue. ***
Comment #7 by github-bugzilla — 2014-01-02T10:31:28Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/0e08634edb3f06c3879f679ca97e7dde5340b915 fix Issue 11591 - std.typecons.Tuple -s with classes fails at runtime as associative array keys https://github.com/D-Programming-Language/dmd/commit/10de92b5bbfda4850cb7f17885d7d9a2c7ad0290 Merge pull request #3054 from WalterBright/fix11591 Regression fix Issue 11591 - std.typecons.Tuple -s with classes fails at runtime as associative array keys
Comment #8 by github-bugzilla — 2014-01-07T02:32:43Z
Commit pushed to 2.065 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/ac329ecd01fb9a24d1ec9d60f2d26fe2a14f8e62 Merge pull request #3054 from WalterBright/fix11591 Regression fix Issue 11591 - std.typecons.Tuple -s with classes fails at runtime as associative array keys