Skip to content

Commit

Permalink
Merge pull request #4195 from Biotronic/fix-15920
Browse files Browse the repository at this point in the history
Fix 15920 - std.traits.MemberFunctionsTuple gives a wrong result
  • Loading branch information
DmitryOlshansky committed Apr 28, 2016
2 parents 18dfffa + 26f3eb9 commit 893a1fe
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion std/traits.d
Expand Up @@ -3745,7 +3745,15 @@ template MemberFunctionsTuple(C, string name)
alias Target = FunctionTypeOf!target;
alias Rest0 = FunctionTypeOf!(rest[0]);

static if (isCovariantWith!(Target, Rest0))
static if (isCovariantWith!(Target, Rest0) && isCovariantWith!(Rest0, Target))
{
// One of these overrides the other. Choose the one from the most derived parent.
static if (is(AliasSeq!(__traits(parent, target))[0] : AliasSeq!(__traits(parent, rest[0]))[0]))
alias shrinkOne = shrinkOne!(target, rest[1 .. $]);
else
alias shrinkOne = shrinkOne!(rest[0], rest[1 .. $]);
}
else static if (isCovariantWith!(Target, Rest0))
// target overrides rest[0] -- erase rest[0].
alias shrinkOne = shrinkOne!(target, rest[1 .. $]);
else static if (isCovariantWith!(Rest0, Target))
Expand Down Expand Up @@ -3801,6 +3809,24 @@ unittest
static assert(__traits(isSame, foos[1], B.foo));
}

unittest // Issue 15920
{
class A
{
void f(){}
void f(int){}
}
class B : A
{
override void f(){}
override void f(int){}
}
alias fs = MemberFunctionsTuple!(B, "f");
alias bfs = AliasSeq!(__traits(getOverloads, B, "f"));
assert(__traits(isSame, fs[0], bfs[0]) || __traits(isSame, fs[0], bfs[1]));
assert(__traits(isSame, fs[1], bfs[0]) || __traits(isSame, fs[1], bfs[1]));
}

unittest
{
interface I { I test(); }
Expand Down

0 comments on commit 893a1fe

Please sign in to comment.