[Issue 19554] [2.084.0] Confusing message - Warning: struct Foo has method toHash

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 7 14:15:56 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19554

--- Comment #4 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
Thanks a lot. :) So, example code:

struct Foo {
    ulong toHash() { return 0; }
}

unittest {
    auto a = Foo().hashOf;
}

Interestingly, this was a static assert until 4 years ago, changed by this
commit:
https://github.com/dlang/druntime/commit/463c9d5fef8dd01082ac9bd1bd6971a4a56124f3#diff-1cb07fafd18644ca9974aea7a74483e9L117

A static assert would give the line on which hashOf is called. One might
reasonably expect to instead get the line on which toHash is defined.
Currently, this is impossible, and would require something like
__traits(getLocation, T). Created a separate issue for that in issue 19555.

For now, the best that could be done is probably to pass the file and line to
hashOf as it's being called.

--


More information about the Digitalmars-d-bugs mailing list