D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19554 - [2.084.0] Confusing message - Warning: struct Foo has method toHash
Summary: [2.084.0] Confusing message - Warning: struct Foo has method toHash
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P1 major
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2019-01-07 09:32 UTC by RR
Modified: 2020-08-17 10:24 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description RR 2019-01-07 09:32:42 UTC
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 Simen Kjaeraas 2019-01-07 13:26:12 UTC
Speaking of non-informative - could you include some kind of code that gives this error message?
Comment 2 RR 2019-01-07 13:32:19 UTC
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 RR 2019-01-07 13:34:45 UTC
Changed the `component` to druntime.
Comment 4 Simen Kjaeraas 2019-01-07 14:15:56 UTC
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 Dlang Bot 2020-08-14 08:28:49 UTC
@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 Dlang Bot 2020-08-17 10:24:30 UTC
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