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

Fix Issue 22136 - [REG 2.097.1] hashOf failed to compile because of different inheritance order #3777

Draft
wants to merge 1 commit into
base: stable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/core/internal/hash.d
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,10 @@ if (!is(T == enum) && (is(T == interface) || is(T == class))
static if (__traits(compiles, {size_t h = val.toHash();}))
{
static if (is(__traits(parent, val.toHash) P) && !is(immutable T* : immutable P*)
&& is(typeof((ref P p) => p is null)))
&& is(typeof((ref P p) => p is null))
// https://issues.dlang.org/show_bug.cgi?id=22136
&& __traits(getAliasThis, T).length
&& is(P == typeof(__traits(getMember, val, __traits(getAliasThis, T)))))
return val ? hashOf(__traits(getMember, val, __traits(getAliasThis, T))) : 0;
else
return val ? val.toHash() : 0;
Expand All @@ -625,7 +628,10 @@ if (!is(T == enum) && (is(T == interface) || is(T == class))
static if (__traits(compiles, {size_t h = val.toHash();}))
{
static if (is(__traits(parent, val.toHash) P) && !is(immutable T* : immutable P*)
&& is(typeof((ref P p) => p is null)))
&& is(typeof((ref P p) => p is null))
// https://issues.dlang.org/show_bug.cgi?id=22136
&& __traits(getAliasThis, T).length
&& is(P == typeof(__traits(getMember, val, __traits(getAliasThis, T)))))
return hashOf(val ? hashOf(__traits(getMember, val, __traits(getAliasThis, T)))
: size_t(0), seed);
else
Expand Down
16 changes: 16 additions & 0 deletions test/hash/src/test_hash.d
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void main()
issue21642();
issue22024();
issue22076();
issue22136();
testTypeInfoArrayGetHash1();
testTypeInfoArrayGetHash2();
pr2243();
Expand Down Expand Up @@ -312,6 +313,21 @@ void issue22076()
cast(void) hashOf(c1, 0);
}

void issue22136()
{
interface IObject {
size_t toHash() @trusted nothrow;
}
interface Dummy {}
interface Bug : Dummy, IObject {}
interface Ok : IObject, Dummy {}

Bug bug;
Ok ok;
assert(hashOf(bug) == hashOf(Object.init)); // Regression: failed to compile.
assert(hashOf(ok) == hashOf(Object.init));
}

/// Tests ensure TypeInfo_Array.getHash uses element hash functions instead
/// of hashing array data.
void testTypeInfoArrayGetHash1()
Expand Down