www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Sumtype warning

reply JG <JG somewhere.com> writes:
I am getting the following message:
Warning: struct SumType has method toHash, however it cannot be 
called with const(SumType!(A,B,C)) this

Could someone point in the right direction to understand what I 
am doing that causes this?
Jul 11 2021
parent jfondren <julian.fondren gmail.com> writes:
On Sunday, 11 July 2021 at 09:20:23 UTC, JG wrote:
 I am getting the following message:
 Warning: struct SumType has method toHash, however it cannot be 
 called with const(SumType!(A,B,C)) this

 Could someone point in the right direction to understand what I 
 am doing that causes this?
The two restrictions on toHash are 1. if you're compiling with betterC, it's not present. So you wouldn't get this message. 2. otherwise, the types all have to pass `allSatisfy!(isHashable, Map!(ConstOf, Types))`, where isHashable is defined in std.sumtype to `private enum isHashable(T) = __traits(compiles, () nothrow safe { hashOf(T.init); });` So the problem is one of 1. A, B, or C doesn't have a .toHash 2. A, B, or C has an improper .toHash that isn't nothrow and safe 3. A, B, or C has a .toHash but it doesn't work for const(A) etc.
Jul 11 2021