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

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-01-07T09:32:42Z
Last change time
2020-08-17T10:24:30Z
Keywords
pull
Assigned to
No Owner
Creator
Radu Racariu

Comments

Comment #0 by radu.racariu — 2019-01-07T09:32:42Z
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?
Comment #2 by radu.racariu — 2019-01-07T13:32:19Z
Just using github search one could pinpoint the location where the message is generated: https://github.com/dlang/druntime/blob/2b6673fd6e008d7f1ece0414f3ad693840005c88/src/core/internal/hash.d#L544
Comment #3 by radu.racariu — 2019-01-07T13:34:45Z
Changed the `component` to druntime.
Comment #4 by simen.kjaras — 2019-01-07T14:15:56Z
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