On Wednesday, 2 November 2016 at 16:14:23 UTC, Márcio Martins wrote:
There are 2 hashOf() definitions, one in object.d and one in core.internal.hash.d

If you include core.internal.hash, you cannot call hashOf() anymore, because it conflicts with the implicit import in object.d, this is annoying in itself...
The bigger issue though, is that they have different semantics:

import core.internal.hash : hashOfInt = hashOf;

void main() {
    string moo = "moo";
assert(moo.hashOfInt == moo.idup.hashOfInt); // ok - hashes moo.ptr[0..moo.length] assert(moo.hashOf == moo.idup.hashOf); // fail - hashes &moo[0..moo.sizeof]
}

Did anyone else fall into this trap?

I think that "internal" means "for internal use", I.e. don't import and use it outside.

You could argue that object.hashOf should hash the contents of slices, not just the meta-data (i.e. length / ptr), but that's a separate matter.

Reply via email to