Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 416d1dd

Browse files
committed
Fix Issue 19005 - [REG2.081-b1] object.hashOf no longer works for std.datetime.date.Date
1 parent 90c140f commit 416d1dd

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/core/internal/hash.d

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,11 @@ size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && (is(T ==
139139
{
140140
return bytesHash(toUbyte(val), seed);
141141
}
142-
else // CTFE unsupproreted for structs with reference fields
142+
else // CTFE unsupported
143143
{
144144
assert(!__ctfe, "unable to compute hash of "~T.stringof);
145-
return bytesHash(toUbyte(val), seed);
145+
const(ubyte)[] bytes = (() @trusted => (cast(const(ubyte)*)&val)[0 .. T.sizeof])();
146+
return bytesHash(bytes, seed);
146147
}
147148
}
148149
}
@@ -154,6 +155,22 @@ nothrow pure @safe unittest // issue 18925
154155
auto h = hashOf(S.init);
155156
}
156157

158+
nothrow pure @safe unittest // issue 19005
159+
{
160+
enum Month : ubyte
161+
{
162+
jan = 1
163+
}
164+
static struct Date
165+
{
166+
short _year;
167+
Month _month;
168+
ubyte _day;
169+
}
170+
Date date;
171+
auto hash = date.hashOf;
172+
}
173+
157174
//delegate hash. CTFE unsupported
158175
@trusted nothrow pure
159176
size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && is(T == delegate))

0 commit comments

Comments
 (0)