Bug 19541 – Confusing error message about missing opEquals for AA key
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-01-03T01:45:08Z
Last change time
2023-04-25T13:13:46Z
Assigned to
No Owner
Creator
Ali Cehreli
Comments
Comment #0 by acehreli — 2019-01-03T01:45:08Z
struct S {
bool opEquals(ref const(S) that) const {
here_is_a_compilation_error;
}
}
struct T {
string[S] aa; // <-- Compilation error
}
void main() {
}
Error: AA key type `S` does not have `bool opEquals(ref const S) const`
The message is confusing because the AA key type S satisfies what it says.
Apparently, the problem is actually with a compilation error inside that function but the user is fooled by the message and is now looking for unnecessary workarounds instead of fixing the compilation error.
Ali
Comment #1 by razvan.nitu1305 — 2023-04-25T13:13:46Z
Compiling this example with the latest git master, I get:
test.d(8): Error: AA key type `S` should have `extern (D) size_t toHash() const nothrow @safe` if `opEquals` defined
Fine, I added the toHash myself:
struct S {
bool opEquals(ref const(S) that) const {
here_is_a_compilation_error;
}
size_t toHash() const { return 1; }
}
struct T {
string[S] aa; // <-- Compilation error
}
void main(){
}
But now I get:
test.d(3): Error: undefined identifier `here_is_a_compilation_error`
This seems to have been fixed.