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

Commit

Permalink
fix Issue 15367 - array of delegates comparison fails
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Nov 20, 2015
1 parent 0c43b04 commit cbaca59
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/object.d
Expand Up @@ -762,7 +762,30 @@ class TypeInfo_Delegate : TypeInfo
return c && this.deco == c.deco;
}

// BUG: need to add the rest of the functions
override size_t getHash(in void* p) @trusted const
{
return hashOf(*cast(void delegate()*)p);
}

override bool equals(in void* p1, in void* p2) const
{
auto dg1 = *cast(void delegate()*)p1;
auto dg2 = *cast(void delegate()*)p2;
return dg1 == dg2;
}

override int compare(in void* p1, in void* p2) const
{
auto dg1 = *cast(void delegate()*)p1;
auto dg2 = *cast(void delegate()*)p2;

if (dg1 < dg2)
return -1;
else if (dg1 > dg2)
return 1;
else
return 0;
}

override @property size_t tsize() nothrow pure const
{
Expand Down Expand Up @@ -794,6 +817,34 @@ class TypeInfo_Delegate : TypeInfo
}
}

unittest
{
// Bugzilla 15367
void f1() {}
void f2() {}

// TypeInfo_Delegate.getHash
int[void delegate()] aa;
assert(aa.length == 0);
aa[&f1] = 1;
assert(aa.length == 1);
aa[&f1] = 1;
assert(aa.length == 1);

auto a1 = [&f2, &f1];
auto a2 = [&f2, &f1];

// TypeInfo_Delegate.equals
for (auto i = 0; i < 2; i++)
assert(a1[i] == a2[i]);
assert(a1 == a2);

// TypeInfo_Delegate.compare
for (auto i = 0; i < 2; i++)
assert(a1[i] <= a2[i]);
assert(a1 <= a2);
}

/**
* Runtime type information about a class.
* Can be retrieved from an object instance by using the
Expand Down

0 comments on commit cbaca59

Please sign in to comment.