Compiler prints this non-informative warning:
---
Warning: struct Foo has method toHash, however it cannot be called with shared(const(Foo)) this.
---
There is no line number to indicate what causes the warning.
Comment #1 by simen.kjaras — 2019-01-07T13:26:12Z
Speaking of non-informative - could you include some kind of code that gives this error message?
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.
Comment #5 by dlang-bot — 2020-08-14T08:28:49Z
@Biotronic created dlang/druntime pull request #3195 "Fix issue 19554 - Confusing message - Warning: struct Foo has method …" fixing this issue:
- Fix issue 19554 - Confusing message - Warning: struct Foo has method toHash
https://github.com/dlang/druntime/pull/3195
Comment #6 by dlang-bot — 2020-08-17T10:24:30Z
dlang/druntime pull request #3195 "Fix issue 19554 - Confusing message - Warning: struct Foo has method …" was merged into master:
- c29afdbfe491ebdbee891b10604147e15eccb969 by Simen Kjærås:
Fix issue 19554 - Confusing message - Warning: struct Foo has method toHash
https://github.com/dlang/druntime/pull/3195