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

Commit

Permalink
Merge pull request #1536 from BBasile/issue-15111
Browse files Browse the repository at this point in the history
fix issue 15111 - hashOf fails for structs that have an alias this to a dynamic array
  • Loading branch information
DmitryOlshansky committed Apr 26, 2016
2 parents 7d84c69 + 3af285f commit 2d8b0a5
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/core/internal/hash.d
Expand Up @@ -37,7 +37,9 @@ size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && __traits
}

//dynamic array hash
size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && !is(T : typeof(null)) && is(T S: S[]) && !__traits(isStaticArray, T))
size_t hashOf(T)(auto ref T val, size_t seed = 0)
if (!is(T == enum) && !is(T : typeof(null)) && is(T S: S[]) && !__traits(isStaticArray, T)
&& !is(T == struct) && !is(T == class) && !is(T == union))
{
alias ElementType = typeof(val[0]);
static if (is(ElementType == interface) || is(ElementType == class) ||
Expand Down Expand Up @@ -91,7 +93,9 @@ size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && is(T : t

//Pointers hash. CTFE unsupported if not null
@trusted nothrow pure
size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && is(T V : V*) && !is(T : typeof(null)))
size_t hashOf(T)(auto ref T val, size_t seed = 0)
if (!is(T == enum) && is(T V : V*) && !is(T : typeof(null))
&& !is(T == struct) && !is(T == class) && !is(T == union))
{
if(__ctfe)
{
Expand Down Expand Up @@ -387,6 +391,27 @@ unittest
}


unittest // issue 15111
{
void testAlias(T)()
{
static struct Foo
{
T t;
alias t this;
}
Foo foo;
static assert(is(typeof(hashOf(foo))));
}
// was fixed
testAlias!(int[]);
testAlias!(int*);
// was not affected
testAlias!int;
testAlias!(void delegate());
testAlias!(string[string]);
testAlias!(int[8]);
}

// MurmurHash3 was written by Austin Appleby, and is placed in the public
// domain. The author hereby disclaims copyright to this source code.
Expand Down

0 comments on commit 2d8b0a5

Please sign in to comment.